[Zope3-dev] actions and subclasses in zc.page

Fred Drake fdrake at gmail.com
Wed Jul 13 07:31:39 EDT 2005


On 7/7/05, Martijn Faassen <faassen at infrae.com> wrote:
> I noticed another possible oddness with zc.page. When I subclass
> form.PageEditForm, I normally get an 'edit' action provided with it, as
> the baseclass defines this.

The base class provides two things:

- the implementation of the edit action, and

- the "registration" of the edit action in self.actions.

> If I however add my own actions in the subclass, like this:
> 
> @form.action("Another")
> def handle_another_action(self, action, data):
>      ...
> 
> the 'edit' action just disappears from the action list.

Well, the entire set of actions is replaced.

> Not daunted by this, I tried the following to restore the edit action:
> 
> @form.action("Edit")
> def handle_edit_action(self, action, data):
>      super(MyClass, self).handle_edit_action(action, data)
> 
> The 'Edit' button now appears in the form. Unfortunately submitting it
> using this button results in:
> 
> TypeError: 'Action' object is not callable

Interesting.

> Not giving up, I tried it another way, and placed this in the class,
> above the place where the extra action gets defined:
> 
>      actions = form.Actions(
>          form.Action("Edit", success="handle_edit_action"),
>          )
> 
> Unfortunately no luck either when I submit:
> 
>    File "/home/faassen/working/doclib/py/zc/page/form.py", line 735, in
> __call__
>      self.update()
>    File "/home/faassen/working/doclib/py/zc/page/form.py", line 715, in
> update
>      result = action.success(data)
>    File "/home/faassen/working/doclib/py/zc/page/form.py", line 567, in
> success
>      return self.success_handler(self.form, self, data)
>    File "/home/faassen/working/doclib/py/zc/page/form.py", line 507, in
> <lambda>
>      callable = lambda form, action, data: getattr(form, f)(action, data)
> TypeError: 'Action' object is not callable
> 
> Is this a bug?

That might be; I'll let Jim say for sure.

If you only want to add actions, what you can do in your view class is this:

    class MyForm(form.EditForm):

        actions = form.EditForm.actions[:]

        @form.action(_("Whatever"))
        def handle_whatever(self, action, data):
            pass


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
Zope Corporation


More information about the Zope3-dev mailing list