I am trying to override a viewlet class that inherits from ore.viewlet.core.FormViewlet. It has two methods decorated with @form.action (which is imported from zope.formlib). I need to override only one of them. If I don't define the other one, too, its action is unavailable. So I defined it, trying to simply pass the return value of the parent class. But then I get a TypeError: 'Action' object is not callable.
Specifically, I'm overriding Products.PloneGetPaid.browser.cart.ShoppingCartActions, which is defined like this:
class ShoppingCartActions( FormViewlet ):
I defined the overriding class to inherit from this. The two decorated methods are:
@form.action(_("Continue Shopping"), name='continue-shopping')
def handle_continue_shopping( self, action, data ):
and
@form.action(_("Checkout"), condition="doesCartContainItems", name="Checkout")
def handle_checkout( self, action, data ):
I really only care about overriding the first. I'd like to leave the other one alone. These two @form.action methods generate the "Continue Shopping" and "Checkout" buttons in the "Next Steps" viewlet of the Shopping Cart Management page. If I only define the "Continue Shopping" method in my subclass, the "Checkout" button disappears. So I tried defining the Checkout method like this:
@form.action(_("Checkout"), condition="doesCartContainItems", name="Checkout")
def handle_checkout( self, action, data ):
return super( ShoppingCartActions, self ).handle_checkout(action, data)
But then I get this error:
2011-05-20 17:01:40 ERROR Zope.SiteErrorLog http://localhost:8080/obrien/@@getpaid-cartTraceback (innermost last):
Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module Products.PloneGetPaid.browser.cart, line 46, in __call__
Module zope.viewlet.manager, line 104, in update
Module ore.viewlet.core, line 15, in update
Module Products.PloneGetPaid._patch, line 44, in update
Module zope.formlib.form, line 750, in update
Module zope.formlib.form, line 594, in success
Module plonetheme.obrienskin.browser.cart, line 23, in handle_checkout
TypeError: 'Action' object is not callable
This makes me think that there must be some trick to overriding and inheriting methods decorated with @form.action.
Any tip would be appreciated.
Thanks!
@form.action wraps the method into an form.Action instance and binds it there to the success_handler attribute. So your code should look like this:
@form.action(_("Checkout"), condition="doesCartContainItems", name="Checkout")
def handle_checkout( self, action, data ):
return super(ShoppingCartActions, self).handle_checkout.success_handler(
self, action, data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With