[Zope] Extending Formulator with a derived product

Jeff Kowalczyk jtk@yahoo.com
Wed, 3 Jul 2002 10:41:06 -0400


I need to extend formulator functionality with a new property
group, akin to 'widget' and 'validator'.

Layout is a new class to give fields some positional rendering
capabilities. These properties are going to live on the form
fields, so the rendering for the form instances can be generic.

I've got the basic mechanism working on a copy of the
Formulator CVS source. However, I want to switch to deriving my
product from Formulator rather than maintaining a private fork
of the code. I don't know how to derive from the sophisticated
Formulator class heirarchy to accomplish the changes.

Can anyone suggest how to set up a derived product to do it?
Thanks for any advice.


Layout.py is (for now) like Widget.py, except for these changes:
[Layout.py (new)]
----------------------------------------------------------------
class Layout:
    ...
    property_names = ['vertical_position', 'horizontal_position']

    vertical_position = fields.StringField('vertical_position',
                                       title='Vertical Position',
                                       description=(
        "vertical position of field in some rendering scheme"),
                                       default="",
                                       required=0)

    horizontal_position = fields.StringField('horizontal_positition',
                                   title='Horizontal Position',
                                   description=(
        "horizontal position of field in some rendering scheme"),
                                   default="",
                                   required=0)
    ...

LayoutInstance = Layout()


[FieldRegistry.py (added)]
----------------------------------------------------------------
    for field in getPropertyFields(field_class.layout):
        form.add_field(field, "layout")
        tales_field = fields.TALESField(field.id,
                                        title=field.get_value('title'),
                                        description="",
                                        default="",
                                        display_width=40,
                                        required=0)
        tales_form.add_field(tales_field, "layout")

        method_field = fields.MethodField(field.id,
                                          title=field.get_value("title"),
                                          description="",
                                          default="",
                                          required=0)
        override_form.add_field(method_field, "layout")

These modules need to import the new module:
[ListAreaTextField.py, MethodField.py, StandardFields.py, TalesField.py
(changed)]
----------------------------------------------------------------
import Widget, Validator, Layout


[StandardFields.py (changed)]
----------------------------------------------------------------
class StringField(ZMIField):
    meta_type = "StringField"

    widget = Widget.TextWidgetInstance
    validator = Validator.StringValidatorInstance
    layout = Layout.LayoutInstance

(repeated for each field class...)


[ListTextAreaField.py (changed)]
----------------------------------------------------------------
class ListTextAreaField(ZMIField):
    ...
    widget = ListTextAreaWidgetInstance
    validator = ListLinesValidatorInstance
    layout = Layout.LayoutInstance


[TalesField.py (changed)]
----------------------------------------------------------------
class TALESField(ZMIField):
    ...
    widget = TALESWidgetInstance
    validator = TALESValidatorInstance
    layout = Layout.LayoutInstance


And a trivial change to allow the new type to coexist with the real one:
[Form.py (changed)]
----------------------------------------------------------------
class ZMIForm(ObjectManager, PropertyManager, RoleManager, Item, Form):
    ...
    meta_type = "Formulator2 Form"