Wednesday, September 30, 2009

Folders with quotas

Another step in getting control over the total size of stuff that users upload, is the quota product. It's not yet eggified, a bit old, but works fine on Plone 3.1.7. It's available from the collective at https://svn.plone.org/svn/collective/quota. I've added a Dutch translation.

Plone Dutch users' day (Gebruikersdag) talk

Here is a link to the slides of the talk i gave at the Dutch Plone users' day: Deliverance for Plone, a use case

Tuesday, September 29, 2009

How to limit Plone's file upload size?

It would be nice if we could somehow limit the size of members' uploads. One step in this would be to limit the size for an individual file upload.

Follow-up: See /2009/09/folders-with-quotas.html for more along this track.

After digging in ATContentTypes' ATFile class, it turns out there's a validator for this, but it's disabled by default. It can be modified by tweaking the file etc/atcontenttypes.conf.in in the ATContentTypes product:

<archetype ATFile>
# maximum file size in byte, kb or mb
max_file_size 10mb
</archetype>

You can set it to just 1024 for 1024 bytes, or use kb's or mb's as above.

Next: how to change this value without touching ATContentTypes? There's a recipe called plone.recipe.atcontenttypes which sets ATContentTypes' configuration from the buildout. Just add this to your buildout:

[buildout]
parts =
...
atcontenttypes-conf

[atcontenttypes-conf]
recipe = plone.recipe.atcontenttypes
zope-instance-location = ${instance:location}
max-file-size = ATFile:10mb

Thursday, September 24, 2009

PloneGazette: exporting all subscribers as csv

A custom script. It's worth noting that in PloneGazette 3.0, calling getFolderContents on a NewsletterBTree will give its parent's contents. That's acquisition for you. So we use the getSubcribers method.

There's also a nice trick to copy the results to the Plone log.


## Script (Python) "exportEmailSubscriptions"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
response = context.REQUEST.RESPONSE
response.setHeader('Content-type','application/csv;; charset=utf-8')
response.addHeader("Content-Disposition","inline; filename=export.csv")
response.setHeader('Cache-Control','no-cache')
response.setHeader('Pragma','No-Cache')

def copy_to_log(message):
message = str(message)
script_name = "EXPORT_SUBSCRIBERS"
context.plone_log("%s: %s" % (script_name, message))
return message

from Products.CMFCore.utils import getToolByName
catalog = getToolByName(context, 'portal_catalog')
results = catalog(portal_type="NewsletterBTree")
for result in results:
folder = result.getObject()
subscr_brains = folder.getSubscribers()
for subscr_brain in subscr_brains:
subscr = subscr_brain.getObject()
print copy_to_log("%s,%s,%s" % ( subscr.Title(), subscr.active, subscr.format, ))

return printed

AttributeError: validateSingleEmailAddress with MailDropHost

I use MailDropHost in a Plone 2.5 buildout for development. The nice thing for development is, you send emails to all users from Plone, and they will not be sent, just kept in MailDrop's spool folder, until you start maildrophost.

However, it gave an error when sending mail:
  Module Products.CMFPlone.PloneTool, line 190, in validateSingleEmailAddress
AttributeError: validateSingleEmailAddress


It seems PloneTool calls this method, which is present in Plone2.5's SecureMailHost, but not in the MailDropHost. It was solved using Jarn's SecureMaildropHost. Here is my dvl.cfg:

[buildout]
extends = base.cfg
parts +=
maildrophost
eggs +=
Products.Clouseau
plone.reload
Products.DocFinderTab

[maildrophost]
recipe = infrae.maildrophost
smtp_host = mysmtphost
smtp_port = 25
version = 1.22

[productdistros]
urls +=
http://plone.org/products/securemaildrophost/releases/0.1/SecureMaildropHost-0.1.tgz

[instance]
products +=
${maildrophost:location}

Thursday, September 3, 2009

Product shows up twice

A product showed up twice: once as "Products.MyProductName" and once as "MyProductName". This happened in the ZMI > portal_quickinstaller, ZMI > Control Panel > Products, and in the Plone Add-on Products panel.

The trick was to remove the line "five:registerPackage" from configure.zcml, as explained in the weblion site. Reloading the zcml configuration with plone.reload was also handy.