[Checkins]
SVN: z3c.form/branches/pcardune-tweaks/src/z3c/form/button.
Made the ButtonAction adapter lookup function without having
a string as a required object and add tests for customized
button action implementation. This should be ready to be
merged info trunk.
Paul Carduner
paulcarduner at gmail.com
Tue Jun 19 21:25:13 EDT 2007
Log message for revision 76821:
Made the ButtonAction adapter lookup function without having a string as a required object and add tests for customized button action implementation. This should be ready to be merged info trunk.
Changed:
U z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py
U z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt
-=-
Modified: z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py
===================================================================
--- z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py 2007-06-19 22:58:08 UTC (rev 76820)
+++ z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py 2007-06-20 01:25:11 UTC (rev 76821)
@@ -223,9 +223,11 @@
fullName = prefix + name
# Look up a button action factory
buttonAction = zope.component.queryMultiAdapter(
- (self.request, button, fullName), interfaces.IFieldWidget)
+ (self.request, button), interfaces.IFieldWidget)
+ if buttonAction is not None:
+ buttonAction.name = fullName
# if one is not found, use the default
- if buttonAction is None:
+ else:
buttonAction = ButtonAction(self.request, button, fullName)
# Look up a potential custom title for the action.
title = zope.component.queryMultiAdapter(
Modified: z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt
===================================================================
--- z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt 2007-06-19 22:58:08 UTC (rev 76820)
+++ z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt 2007-06-20 01:25:11 UTC (rev 76821)
@@ -63,6 +63,31 @@
>>> actions['apply']
<ButtonAction 'form.buttons.apply' u'Apply'>
+It is possible to customize how a button is transformed into an action
+by registering an adapter for the request and the button that provides
+IFieldWidget.
+
+ >>> import zope.component
+ >>> from zope.publisher.interfaces.browser import IBrowserRequest
+ >>> class CustomButtonAction(button.ButtonAction):
+ ... """Custom Button Action Class."""
+ ... zope.interface.implements(interfaces.IFieldWidget)
+ ... zope.component.adapts(IBrowserRequest, interfaces.IButton)
+ ...
+ ... def __init__(self, request, field):
+ ... super(CustomButtonAction, self).__init__(request, field, None)
+
+ >>> zope.component.provideAdapter(CustomButtonAction,
+ ... (IBrowserRequest,interfaces.IButton),
+ ... interfaces.IFieldWidget)
+
+Now if we rerun update we will get this other ButtonAction
+implementation.
+
+ >>> actions.update()
+ >>> actions['apply']
+ <CustomButtonAction 'form.buttons.apply' u'Apply'>
+
Button actions are locations:
>>> apply = actions['apply']
More information about the Checkins
mailing list