[Checkins] SVN: z3c.form/branches/pcardune-tweaks/src/z3c/form/ added hook for actionFactory attribute on button instances

Paul Carduner paulcarduner at gmail.com
Wed Jun 20 20:30:08 EDT 2007


Log message for revision 76870:
  added hook for actionFactory attribute on button instances

Changed:
  U   z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py
  U   z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt
  U   z3c.form/branches/pcardune-tweaks/src/z3c/form/interfaces.py

-=-
Modified: z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py
===================================================================
--- z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py	2007-06-20 23:05:48 UTC (rev 76869)
+++ z3c.form/branches/pcardune-tweaks/src/z3c/form/button.py	2007-06-21 00:30:04 UTC (rev 76870)
@@ -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
@@ -222,13 +223,17 @@
                 continue
             fullName = prefix + name
             # Look up a button action factory
-            buttonAction = zope.component.queryMultiAdapter(
-                (self.request, button), interfaces.IFieldWidget)
-            if buttonAction is not None:
+            if button.actionFactory is not None:
+                buttonAction = button.actionFactory(self.request, button)
                 buttonAction.name = fullName
-            # if one is not found, use the default
             else:
-                buttonAction = ButtonAction(self.request, button, fullName)
+                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/branches/pcardune-tweaks/src/z3c/form/button.txt
===================================================================
--- z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt	2007-06-20 23:05:48 UTC (rev 76869)
+++ z3c.form/branches/pcardune-tweaks/src/z3c/form/button.txt	2007-06-21 00:30:04 UTC (rev 76870)
@@ -88,6 +88,26 @@
   >>> 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/branches/pcardune-tweaks/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/branches/pcardune-tweaks/src/z3c/form/interfaces.py	2007-06-20 23:05:48 UTC (rev 76869)
+++ z3c.form/branches/pcardune-tweaks/src/z3c/form/interfaces.py	2007-06-21 00:30:04 UTC (rev 76870)
@@ -466,7 +466,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