[Zope3-Users] Hook into edit-form post

Andreas Reuleaux reuleaux at web.de
Sun Jul 9 19:50:39 EDT 2006


As Marco said, use formlib, e. g. like this

<browser:editform
    schema="sidsite.ISidPage.ISidPage"
    label="Edit"
    name="edit.html"
    menu="zmi_views" title="Edit a SidPage"
    permission="zope.ManageContent"

    class="myview.EditView" <--- ***

    />


and in myview.py

  from ... import ISidPage
  from zope.formlib import form
  class EditView(form.EditForm):

    form_fields=form.Fields(ISidPage)

    # here you can redefine some of the
    # methods/actions/etc. of form.Editform
    


(personally I prefer <browswer:page> over
<browser:editform>) and I am redefining
e. g.

   template = namedtemplate.NamedTemplate('...')

   def setUpWidgets(self, ...)
   ...

   @action("...", ...)
   ...

Note that there is one action already defined in EditForm
called handle_edit_action. You can reuse this one
(and add some more actions) with

  actions=form.EditForm.actions[:]  (*, see below)
  
  @action(...)

or if you leave out line (*) you effectivly start
with no actions - i. e. you just use your self-defined
actions.

Also I found the setup of a template (a ZPT) in EditView
a bit tricky, what works for me is this:

in myview.py

  my_pt = namedtemplate.NamedTemplateImplementation(
    ViewPageTemplateFile('sometemplate.pt'),
    form.interfaces.IPageForm)

as well as (mentioned above already) in myview.EditView:
  
  template = namedtemplate.NamedTemplate('whatever')  

configuration with

  <adapter factory=".myview.my_pt" name="whatever" />

Have a look at these files:
  src/zope/formlib/form.py
  src/zope/formlib/form.txt

-Andreas  


On Sun, Jul 09, 2006 at 10:05:47AM -0700, Siddhartha Azad wrote:
> Hi,
> I have the following lines in my configure.zcml to add
> a content object "SidPage":
> 
> <browser:editform
>         schema="sidsite.ISidPage.ISidPage"
> 	label="Edit"
> 	name="edit.html"
> 	menu="zmi_views" title="Edit a SidPage"
> 	permission="zope.ManageContent"/>
> 
> When I click on an existing "SidPage" on the ZMI, it
> takes me to a form where I have Refresh or Change, and
> since a SidPage is Persistent, it saves the value into
> ZODB.
> 
> My question is, what if I wanna do some intermediate
> processing onto the values for ISidPage attribs that
> the user entered into the form, before saving them? Is
> there a way to provide a python class or a ZPT as a
> hook when the actual post on these auto-generated
> forms is done?
> 
> Thanks, Sid.
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
> 
> 
> !DSPAM:44b1521e64502984811091!


More information about the Zope3-users mailing list