[Zope3-dev] browser:form directive (was: There's something wrong with having message ids in schemas)

Gary Poster gary at zope.com
Thu Dec 9 11:00:11 EST 2004


I also have a version of the form machinery that includes not only a 
base form directive but also innovations like formpatterns--form 
macros, basically--multiple configurable buttons, and maybe some other 
features I forget.  It was developed, in part, to make zcml 
configuration (and mass *changes*) of multiple forms easier; and in 
part to bring power similar to CMFFormController to Zope 3 forms in a 
fairly straightforward way.  It's for our Zope 2 + Zope 3 efforts 
(which will migrate to Zope 3 or Five eventually) and so the code is 
based off of an old Zope 3 and also has some Zope 2-isms.  Interfaces 
and ideas are probably of most interest.

As I had mentioned to Stephan months ago, I was to have ported this to 
an open-source package usable with Zope 3 core; but this has not been 
assigned as a priority yet.  ZC is still planning on porting some or 
all of this when we have the time.  There are no hard dates or hard 
plans right now, so I don't advise holding your breath, and I would 
encourage alternate efforts.

If anyone is interested to see this for ideas, or to discuss use cases, 
ideas, and approaches, I can share some examples, some code, and some 
time.  Here's some zcml snippets for interested folks to ponder, for 
now:

<!--
   these are the three default patterns for the edit, display, and add 
form
   tags.

   the id in a formpattern is a token specified in the pattern attribute 
of a form.
   It follows the usual Zope 3 zcml id convention of being a Python path 
to the
   pertinent package.

   formpatterns themselves can specify a pattern attribute to base one
   formpattern off another.

   A button's action is a method that must be available on the view 
class.  Button
   declarations can have permissions, TALES guards, and categories (not 
used
   in these examples).  Labels are i18n-aware, the way you'd expect.
-->
<zope2:formpattern
     id="my_package.default_edit"
     default_template="form.pt"
     label="Edit ${title} Properties">
   <zope2:buttons>
     <zope2:button label="Save changes" action="attempt_commit"
                   permission="Modify portal content" />
   </zope2:buttons>
</zope2:formpattern>

<zope2:formpattern
     id="my_package.default_display"
     default_template="display.pt"
     label="${title} Overview" />

<zope2:formpattern
     id="my_package.default_add"
     default_template="form.pt"
     label="Add ${title}">
   <zope2:buttons>
     <zope2:button label="Add" action="attempt_commit"
                   permission="Add portal content" />
     <zope2:button label="Cancel" action="perform_cancel" permission="" 
/>
   </zope2:buttons>
</zope2:formpattern>

zcml for an edit, add, or display just specifies the pattern and 
overrides what they need, usually simplifying zcml significantly.  We 
also have a container tag that specifies shared configuration (schema 
and field order, for instance) and can contain multiple add, edit, and 
display tags, further simplifying the form tags themselves. For 
instance:

<typeinfo xmlns='http://namespaces.zope.org/zope2' name="Image"
     schema="my_package.image.IImage"
     content_factory="my_package.image.Image" title="Image"
     description=
         "Image content objects that support version control"
     icon="image_icon.gif"
     permission="Add portal content"
     fields="title description mime_type filename width
             height creator creation_date modifier modified_date">
   <add pattern="my_package.upload_add"
        template="add_upload_image.pt"
        omit_fields="creator creation_date modifier modified_date siteurl
                     filename mime_type width height"/>
   <edit pattern="my_package.default_edit"
         omit_fields="creator creation_date modifier modified_date 
siteurl
                      filename mime_type" />
   <edit pattern="my_package.default_related"
         fields="embedded_media related links" name="related.html"/>
   <display pattern="my_package.default_display"/>
   <!-- we put CMF actions here; menu configurations might go here in 
Zope 3 -->
</typeinfo>

zcml for an arbitrary non-add-edit-or-display form that happens to use 
one of these macros is this (notice the TALES guard condition for the 
button, btw, and the view class that customizes
what the attempt_commit action (==method) does):

<form xmlns='http://namespaces.zope.org/zope2'
     pattern="my_package.default_edit"
     label="Status"
     schema=".workflow_form.IWorkflowManaged"
     name="content_status_history.html"
     for=".interfaces.IContent"
     class=".workflow_form.WorkflowManagedForm">
     <buttons>
         <button label="Change" action="attempt_commit"
             condition="adapted/choices" />
     </buttons>
</form>

To repeat, our code for this is likely not of significant interest; 
ideas, and maybe meta zcml interfaces, may be of interest; and if no 
one addresses this, ZC will eventually want it, I think.

But meanwhile, I say, go thou and improve! :-)  Hope this helps.

Gary



More information about the Zope3-dev mailing list