[Zope3-Users] editform onSuccess-method

Jeff Shell eucci.group at gmail.com
Wed Mar 29 10:18:49 EST 2006


On 3/29/06, Frank Burkhardt <fbo2 at gmx.net> wrote:
> On Wed, Mar 29, 2006 at 04:12:40PM +0530, baiju m wrote:
> > On 3/29/06, Frank Burkhardt <fbo2 at gmx.net> wrote:
> > > Hi,
> > >
> > > I need to do some changes to an object, after it's either created or
> > > modifed. Is there a chance to define methods on the object's class that are
> > > called after the addform or the editform are done creating/changing the
> > > object? Maybe there's a ZCML-way to do this?
> >
> > May be you are looking for events ?
> > http://www.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3Book/events.html
>
> Maybe that's what I have to use. But I would rather like a solution like this:
>
>   subclass class XXX
>   overwrite method YYY
>   define statement ZZZ in ZCML

If you need to do these changes all the time - regardless of how the
object is created or modified - then you do want to go with events.

* subclass nothing
* write event handler functions (for IObjectAddedEvent and IObjectModifiedEvent)
* register handler in ZCML.

If you're using formlib (Zope 3.2 feature) based forms (which I
recommend using), look at the formlib API and the
zope/formlib/forms.txt document. There are some excellent base classes
in there for editing, adding, and just doing your own thing. With each
'action', it's very possible to do your own responses. In that case,
it's:

* subclass zope.formlib.form base classes (Form, EditForm, etc)
* override an action / write a new action / overwrite update or render
* no ZCML - just register it as a view.

class EditItineraryForm(form.EditForm):
    form_fields = form.Fields(IItinerary)

    @form.action(u"Save Changes", condition=form.haveInputWidgets)
    def handleEditAction(self, action, data):
        if form.applyChanges(self.context,self.form_fields,data,self.adapters):
            notify(ObjectModifiedEvent(self.context))
            self.status = u"Itinerary Details Updated"
            self.onSuccess()
        else:
            self.status = u"No Changes"

Something like that should work. You could even make your own base
EditForm class that defined the above action, and a subclass would
just need to provide onSuccess and the form_fields.

--
Jeff Shell


More information about the Zope3-users mailing list