[Zope3-Users] z3c.form - Idea for subforms

Hermann Himmelbauer dusty at qwer.tk
Thu Jul 5 15:18:44 EDT 2007

After playing around with subforms, I think some parts could be more implicit. 
What I don't like so much is that there's quite some boilerplate code which 
is not easily understandable for a newbie, moreover the explicit code is also 
hard to understand (at least for me) unless one does have a decent insight 
into the z3c.form package.

I have some ideas which could perhaps simplify subforms - however, I don't 
know if they work or break some key concepts:

1) Create seperate classes for "form within form" and "logical units" for each 
Add/Edit/Display, e.g.:

AddFormInForm / EditFormInForm / DisplayFormInForm
AddSubForm / EditSubForm / DisplaySubForm

I think this would provide a better understanding, as one can look at a class 
and immediately understand what they are ment for. Moreover various 
boilerplate code could be saved, e.g. like this in case of a AddSubForm:

    def updateWidgets(self):
        self.widgets = getMultiAdapter(
            (self, self.request, self.getContent()), IWidgets)
        self.widgets.ignoreContext = True

2) Handling the creation / update of the subform in the update() method of the 
parent form is too explicit, I think. Another problem is the placing of the 
form in the HTML widget, this does not seem to work with a generator 
(tal:repeat), one has to insert them manually. In my case, where I don't want 
the subform at the top/bottom but in between other widgets, I probably have 
to write a lot of template code.

To my mind, it would be ideal, if Zope figures out all this for itself. I 
think that the interface itself provides all necessary information that Zope 
needs, e.g. in case of a field such as:

owner = Object(schema=IOwner)

Zope knows that there has to be a subform involved. My idea is to somehow 
register subforms to specific Interfaces/fields, but I'm not sure if that is 
possible. This could look something like this:

   for = "ICar",
   interface = "IOwner",
   class = ".browser.OwnerForm"
   layer = "..."
In this case the update function would query for an appropriate adapter for 
the subform, moreover these subforms could also possibly be rendered just 
like any other widget, therefore no specific templates are needed.

3) I think SubForms should look/behave very similar to other forms, therefore 
it would be optimal if one could simply have a create() method in an 
AddSubForm where the object is created. This method would then be 
automatically be called by the parent form and the object would be stored in 
the object attribute.

What do you think?

Best Regards,

x1 at aon.at
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7

More information about the Zope3-users mailing list