[Zope-CMF] [dev] CMFSetup: proposal for improving handlers

yuppie y.2004_ at wcm-solutions.de
Fri Dec 10 09:25:39 EST 2004


It should become easier to maintain existing setup handlers and to write 
new ones. This is a proposal for simplifying handlers and adding a new 
one for site properties.

simplifying handlers:

The setup handlers contain a lot of redundant code. I propose to add a 
ConfiguratorBase class in utils that does most of the work currently 
done in each Configurator and in related helper methods.

A subclass of ConfiguratorBase just needs 3 methods:

- _getExportTemplate:
     Returns the Page Template.

- listToolInfo or something similar:
     Returns the data needed by the Page Template. No changes proposed.

- _getImportMapping:
     Returns a mapping that contains rules for importing nodes.

Here is an example for a _getImportMapping method that would replace 
_extractActionProviderNodes, _extractActionNodes and 
_extractPermissionNodes in 

     def _getImportMapping(self):

         return {
              { 'action-provider': {_KEY: 'providers'},
                'object':          {_KEY: 'objects', _DEFAULT: ()} },
              { 'id':              {},
                'action':          {_KEY: 'actions', _DEFAULT: ()} },
              { 'action_id':       {_KEY: 'id'},
                'title':           {},
                'description':     {_CONVERTER: self._convertToUnique},
                'category':        {},
                'condition_expr':  {_KEY: 'condition'},
                'permission':      {_KEY: 'permissions', _DEFAULT: ()},
                'category':        {},
                'visible':         {_CONVERTER: self._convertToBoolean},
                'url_expr':        {_KEY: 'action'} },
              { '#text':           {_KEY: None} } }

_KEY: If specified, that key is used in the resulting dict instead of 
the subnode/attribute name. If None, the value of a single 
subnode/attribute is returned instead of the dict.

_DEFAULT: Makes sure a default value is returned. This can be a 
formatted string, using values of other node attributes.

_CONVERTER: Modifies the value. If necessary the Configurator can have 
its own converters.

new handler for site properties:

I have some code for importing/exporting properties. That code could 
become part of ConfiguratorBase.

Here is an example export:

<?xml version="1.0"?>
   <property name="title">Portal</property>
   <property name="description"></property>
   <property name="email_from_address" 
type="string">postmaster at localhost</property>
   <property name="email_from_name" type="string">Portal 
   <property name="validate_email" type="boolean"></property>
   <property name="default_charset" type="string"></property>

Does it make sense to have one handler just for site properties, called 
something like "Products.CMFSetup.properties.importSiteProperties"?

Or should there better be one config file for all global settings that 
are not tool settings? Something like 

Any questions, comments or objections?

I'd like to make the proposed changes in 1.5 branch and HEAD. I would 
convert all setup handlers besides the workflow handlers to the new 
style. The workflow handlers contain 50% of the existing handler code 
and they work as they are, so there is no need to waste time converting 


More information about the Zope-CMF mailing list