[Checkins] SVN: z3c.form/trunk/ Added ability to change button
action title via an IValue adapter.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu May 31 00:40:06 EDT 2007
Log message for revision 76038:
Added ability to change button action title via an IValue adapter.
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/setup.py
U z3c.form/trunk/src/z3c/form/button.py
U z3c.form/trunk/src/z3c/form/button.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-05-31 04:26:57 UTC (rev 76037)
+++ z3c.form/trunk/CHANGES.txt 2007-05-31 04:40:05 UTC (rev 76038)
@@ -2,7 +2,17 @@
CHANGES
=======
+Version 1.2.0 (5/30/2007)
+-------------------------
+- Added ability to change the button action title using an IValue adapter.
+
+Version 1.1.0 (5/30/2007)
+-------------------------
+
+- Added compatibility for Zope 3.3 and thus Zope 2.10.
+
+
Version 1.0.0 (5/24/2007)
-------------------------
Modified: z3c.form/trunk/setup.py
===================================================================
--- z3c.form/trunk/setup.py 2007-05-31 04:26:57 UTC (rev 76037)
+++ z3c.form/trunk/setup.py 2007-05-31 04:40:05 UTC (rev 76038)
@@ -40,7 +40,7 @@
setup (
name='z3c.form',
- version='1.0.0',
+ version='1.2.0',
author = "Stephan Richter, Roger Ineichen and the Zope Community",
author_email = "zope3-dev at zope.org",
description = "An advanced form and widget framework for Zope 3",
Modified: z3c.form/trunk/src/z3c/form/button.py
===================================================================
--- z3c.form/trunk/src/z3c/form/button.py 2007-05-31 04:26:57 UTC (rev 76037)
+++ z3c.form/trunk/src/z3c/form/button.py 2007-05-31 04:40:05 UTC (rev 76038)
@@ -23,9 +23,18 @@
from zope.interface import adapter
from zope.schema.fieldproperty import FieldProperty
-from z3c.form import action, interfaces, util
+from z3c.form import action, interfaces, util, value
from z3c.form.browser import submit
+
+StaticButtonActionAttribute = value.StaticValueCreator(
+ discriminators = ('form', 'request', 'content', 'button', 'manager')
+ )
+ComputedButtonActionAttribute = value.ComputedValueCreator(
+ discriminators = ('form', 'request', 'content', 'button', 'manager')
+ )
+
+
class Button(zope.schema.Field):
"""A simple button in a form."""
zope.interface.implements(interfaces.IButton)
@@ -213,6 +222,12 @@
continue
fullName = prefix + name
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),
+ interfaces.IValue, name='title')
+ if title is not None:
+ buttonAction.title = title.get()
self._data_keys.append(name)
self._data_values.append(buttonAction)
self._data[name] = buttonAction
Modified: z3c.form/trunk/src/z3c/form/button.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/button.txt 2007-05-31 04:26:57 UTC (rev 76037)
+++ z3c.form/trunk/src/z3c/form/button.txt 2007-05-31 04:40:05 UTC (rev 76038)
@@ -300,6 +300,32 @@
This feature is very helpful in multi-forms and wizards.
+Customizing the Title
+---------------------
+
+As for widgets, it is often desirable to change attributes of the button
+actions without altering any original code. Again we will be using attribute
+value adapters to complete the task. Originally, our title is as follows:
+
+ >>> myform = Form()
+ >>> actions = button.ButtonActions(myform, TestRequest(), None)
+ >>> actions.update()
+ >>> actions['apply'].title
+ u'Apply'
+
+Let's now create a custom label for the action:
+
+ >>> ApplyLabel = button.StaticButtonActionAttribute(
+ ... u'Apply now', button=myform.buttons['apply'])
+ >>> zope.component.provideAdapter(ApplyLabel, name='title')
+
+Once the button action manager is updated, the new tite is chosen:
+
+ >>> actions.update()
+ >>> actions['apply'].title
+ u'Apply now'
+
+
The Button Manager
------------------
More information about the Checkins
mailing list