[Checkins] SVN: z3c.form/trunk/src/z3c/form/ merging changes
between r76694 and r76870 from pcardune-tweaks branch to trunk.
Paul Carduner
paulcarduner at gmail.com
Fri Jun 22 17:45:41 EDT 2007
Log message for revision 76950:
merging changes between r76694 and r76870 from pcardune-tweaks branch to trunk.
Changed:
U z3c.form/trunk/src/z3c/form/button.py
U z3c.form/trunk/src/z3c/form/button.txt
U z3c.form/trunk/src/z3c/form/interfaces.py
-=-
Modified: z3c.form/trunk/src/z3c/form/button.py
===================================================================
--- z3c.form/trunk/src/z3c/form/button.py 2007-06-22 20:27:52 UTC (rev 76949)
+++ z3c.form/trunk/src/z3c/form/button.py 2007-06-22 21:45:40 UTC (rev 76950)
@@ -40,6 +40,7 @@
zope.interface.implements(interfaces.IButton)
accessKey = FieldProperty(interfaces.IButton['accessKey'])
+ actionFactory = FieldProperty(interfaces.IButton['actionFactory'])
def __init__(self, *args, **kwargs):
# Provide some shortcut ways to specify the name
@@ -221,7 +222,18 @@
if button.condition is not None and not button.condition(self.form):
continue
fullName = prefix + name
- buttonAction = ButtonAction(self.request, button, fullName)
+ # Look up a button action factory
+ if button.actionFactory is not None:
+ buttonAction = button.actionFactory(self.request, button)
+ buttonAction.name = fullName
+ else:
+ buttonAction = zope.component.queryMultiAdapter(
+ (self.request, button), interfaces.IFieldWidget)
+ if buttonAction is not None:
+ buttonAction.name = fullName
+ # if one is not found, use the default
+ else:
+ buttonAction = ButtonAction(self.request, button, fullName)
# Look up a potential custom title for the action.
title = zope.component.queryMultiAdapter(
(self.form, self.request, self.content, button, self),
Modified: z3c.form/trunk/src/z3c/form/button.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/button.txt 2007-06-22 20:27:52 UTC (rev 76949)
+++ z3c.form/trunk/src/z3c/form/button.txt 2007-06-22 21:45:40 UTC (rev 76950)
@@ -63,6 +63,51 @@
>>> 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'>
+
+Alternatively, modify customize an individual button by setting its
+actionFactory attribute.
+
+ >>> def customButtonActionFactory(request, field):
+ ... print "Just to let you know, this is a custom button."
+ ... button = CustomButtonAction(request, field)
+ ... button.css = "happy"
+ ... return button
+
+ >>> form.buttons['apply'].actionFactory = customButtonActionFactory
+ >>> actions.update()
+ Just to let you know, this is a custom button.
+ >>> actions['apply'].css
+ 'happy'
+
+But lets not digress to much and get rid of this customization
+
+ >>> form.buttons['apply'].actionFactory = None
+ >>> actions.update()
+
Button actions are locations:
>>> apply = actions['apply']
Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py 2007-06-22 20:27:52 UTC (rev 76949)
+++ z3c.form/trunk/src/z3c/form/interfaces.py 2007-06-22 21:45:40 UTC (rev 76950)
@@ -467,7 +467,14 @@
max_length=1,
required=False)
+ actionFactory = zope.schema.Field(
+ title=_('Action Factory'),
+ description=_('The action factory.'),
+ required=False,
+ default=None,
+ missing_value=None)
+
class IButtons(ISelectionManager):
"""Button manager."""
More information about the Checkins
mailing list