[Checkins] SVN: z3c.form/trunk/ Initialize widgets in update step, and allow setting prefix string as an argument.

Malthe Borch cvs-admin at zope.org
Tue Oct 30 09:35:25 UTC 2012


Log message for revision 128150:
  Initialize widgets in update step, and allow setting prefix string as an argument.

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/src/z3c/form/form.py
  U   z3c.form/trunk/src/z3c/form/form.txt
  U   z3c.form/trunk/src/z3c/form/group.py
  U   z3c.form/trunk/src/z3c/form/interfaces.py

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2012-10-30 09:18:20 UTC (rev 128149)
+++ z3c.form/trunk/CHANGES.txt	2012-10-30 09:35:25 UTC (rev 128150)
@@ -2,9 +2,20 @@
 CHANGES
 =======
 
-2.9.1 (unreleased)
+2.10.0 (unreleased)
 ------------------
 
+- Initialize widgets in ``update`` step. The ``updateWidgets`` method
+  is now responsible only for actually updating the widgets.
+
+  This allows updating the common widgets prefix before the individual
+  widgets are updated, useful for situations where neither a form, nor
+  a widgets prefix is desired.
+
+  In addition, the ``updateWidgets`` method has learned an argument
+  ``prefix`` which allows setting the prefix of the field widgets
+  adapter.
+
 - Capitalize the messages 'no value' and 'select a value'. This change
   has been applied also to the existing translations (where
   applicable).

Modified: z3c.form/trunk/src/z3c/form/form.py
===================================================================
--- z3c.form/trunk/src/z3c/form/form.py	2012-10-30 09:18:20 UTC (rev 128149)
+++ z3c.form/trunk/src/z3c/form/form.py	2012-10-30 09:35:25 UTC (rev 128150)
@@ -121,10 +121,10 @@
         '''See interfaces.IForm'''
         return self.context
 
-    def updateWidgets(self):
+    def updateWidgets(self, prefix=None):
         '''See interfaces.IForm'''
-        self.widgets = zope.component.getMultiAdapter(
-            (self, self.request, self.getContent()), interfaces.IWidgets)
+        if prefix is not None:
+            self.widgets.prefix = prefix
         self.widgets.mode = self.mode
         self.widgets.ignoreContext = self.ignoreContext
         self.widgets.ignoreRequest = self.ignoreRequest
@@ -145,6 +145,8 @@
 
     def update(self):
         '''See interfaces.IForm'''
+        self.widgets = zope.component.getMultiAdapter(
+            (self, self.request, self.getContent()), interfaces.IWidgets)
         self.updateWidgets()
 
     def render(self):

Modified: z3c.form/trunk/src/z3c/form/form.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/form.txt	2012-10-30 09:18:20 UTC (rev 128149)
+++ z3c.form/trunk/src/z3c/form/form.txt	2012-10-30 09:35:25 UTC (rev 128150)
@@ -1225,7 +1225,25 @@
   >>> display.widgets.ignoreReadonly
   True
 
+We can also set the widget prefix when we update the widgets:
 
+  >>> display.updateWidgets(prefix="person")
+  >>> display.widgets.prefix
+  'person'
+
+This will affect the individual widgets' names:
+
+  >>> display.widgets['id'].name
+  'form.person.id'
+
+To use unqualified names, we must clear both the form prefix and the
+widgets prefix:
+
+  >>> display.prefix = ""
+  >>> display.updateWidgets(prefix="")
+  >>> display.widgets['id'].name
+  'id'
+
 Extending Forms
 ---------------
 

Modified: z3c.form/trunk/src/z3c/form/group.py
===================================================================
--- z3c.form/trunk/src/z3c/form/group.py	2012-10-30 09:18:20 UTC (rev 128149)
+++ z3c.form/trunk/src/z3c/form/group.py	2012-10-30 09:35:25 UTC (rev 128150)
@@ -34,8 +34,6 @@
 
     def updateWidgets(self):
         '''See interfaces.IForm'''
-        self.widgets = zope.component.getMultiAdapter(
-            (self, self.request, self.getContent()), interfaces.IWidgets)
         for attrName in ('mode', 'ignoreRequest', 'ignoreContext',
                          'ignoreReadonly'):
             value = getattr(self.parentForm.widgets, attrName)
@@ -44,7 +42,7 @@
 
     def update(self):
         '''See interfaces.IForm'''
-        self.updateWidgets()
+        super(Group, self).update()
         groups = []
         for groupClass in self.groups:
             # only instantiate the groupClass if it hasn't already
@@ -121,9 +119,10 @@
 
         return changed
 
-    def update(self):
+    def updateWidgets(self):
         '''See interfaces.IForm'''
-        self.updateWidgets()
+        super(GroupForm, self).updateWidgets()
+
         groups = []
         for groupClass in self.groups:
             # only instantiate the groupClass if it hasn't already
@@ -135,7 +134,3 @@
             group.update()
             groups.append(group)
         self.groups = tuple(groups)
-        self.updateActions()
-        self.actions.execute()
-        if self.refreshActions:
-            self.updateActions()

Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py	2012-10-30 09:18:20 UTC (rev 128149)
+++ z3c.form/trunk/src/z3c/form/interfaces.py	2012-10-30 09:35:25 UTC (rev 128150)
@@ -957,11 +957,14 @@
     def getContent():
         '''Return the content to be displayed and/or edited.'''
 
-    def updateWidgets():
+    def updateWidgets(prefix=None):
         '''Update the widgets for the form.
 
         This method is commonly called from the ``update()`` method and is
         mainly meant to be a hook for subclasses.
+
+        Note that you can pass an argument for ``prefix`` to override
+        the default value of ``"widgets."``.
         '''
 
     def extractData(setErrors=True):



More information about the checkins mailing list