Package: dm.zope.generate
This package contains code generators to facilitate the development of Zope[2]
applications.ModulesconstructorThis module contains factories for the generation of add form and
add action forOFS.PropertyManager.PropertyManagerbased classes.
The generated functions are usually used as constructors inregisterClasscalls during product initialization. The subpackagetestcontains an
example (also used for testing this product).The class’_propertiesattribute and the associated default values
are used for add form generation.The module tries hard to avoid encoding problems. Its functions
need to handle up to 3 encodings: the encoding used for the code,
the encoding used for non unicode properties and unicode properties.
The browser can only handle a single encoding per page. Therefore,
the module must use a single encoding and all other encodings must
be mapped. The module usesutf-8as this unified encoding.
The module does nothing special with strings from code. The page template
will convert it to unicode in its standard way. Use unicode strings,
if this gives not the expected result. Unicode based properties
are passed on unchanged to the template.strbased properties
are mapped to unicode with a charset that is either explicitely specified,
looked up in the current acquisition context under the namemanagement_page_charsetand falls back toZPublisher.default_encoding.
The form action converts values for those properties back tostrusing the same charset.add_form_factoryThis factory generates an add form for anOFS.PropertyManager.PropertyManagersubclass.
It has the following parameters.namedefaultdescriptionclass_the class to generate the form foractionadd_classnamethe forms actiondescriptionclass_.__doc__the documentation shown in the formcharsetsee abovetemplatepackage providedthe template to generate the formThe template it brought into the acquisition context of the
generated functions argument and then called with the
keyword parameterscharset,meta_type,description,action,propertiesandclass_. The call should return the HTML
form representation. The package provided template works well
together with the add action created by the add action factory.When you plan to customize the template, please take a look
at the package provided template and the docstring in the source
as this page does not describe all details.Due to a bug/weakness, Zope’s property management
page handles unicode properties only correctly
when it can use the utf-8 charset.
Therefore, it is highly recommended to use utf-8 consistently.
Otherwise, it is possible that property values set with functions
of this module cannot be reliably edited later.
Note in addition, that Zope’s property management spells the
utf-8 charset (stupidly) asUTF-8(note the upper case).
Therefore, useUFT-8rather thanutf-8when you specify
the utf-8 charset for yourmanagement_page_charset.add_action_factoryThis factory generates an add action for anOFS.PropertyManager.PropertyManagersubclass.
The generated action creates an instance of this class, sets its properties,
adds it as content object of its first parameter (assumed to be
anOFS.ObjectManager.ObjectManager) and optionally calls
a hook. Then, it either returns the created instance or redirects
to its management interface.The factory has the parametersclass_and the optionalhook.The generated action has the parametersidand the
optionalpropsandREQUEST.propsspecifies property values
for the created instance. If not specified andREQUESTis passed,
it defaults toREQUEST.form. If specified, it must be a mapping.
If the property value mapping lacks values for some properties, these
retain their default values; values for undefined properties are silently
ignored.History1.1Python3/Zope4 compatibility1.0for Zope2