[Checkins] SVN: z3c.form/trunk/src/z3c/form/field. Fixed a bug that did not honor the mode selection on the

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Jun 4 03:03:21 EDT 2007


Log message for revision 76278:
  Fixed a bug that did not honor the mode selection on the 
  fieldsmanager and always overrode it with the widget 
  manager's setting.
  

Changed:
  U   z3c.form/trunk/src/z3c/form/field.py
  U   z3c.form/trunk/src/z3c/form/field.txt

-=-
Modified: z3c.form/trunk/src/z3c/form/field.py
===================================================================
--- z3c.form/trunk/src/z3c/form/field.py	2007-06-04 06:58:45 UTC (rev 76277)
+++ z3c.form/trunk/src/z3c/form/field.py	2007-06-04 07:03:20 UTC (rev 76278)
@@ -215,31 +215,35 @@
         prefix += util.expandPrefix(self.prefix)
         # Walk through each field, making a widget out of it
         for field in self.form.fields.values():
-            # Step 1: Get the widget for the given field.
-            factory = field.widgetFactory.get(self.mode)
+            # Step 1: Determine the mode of the widget.
+            mode = field.mode
+            if mode is None:
+                mode = self.mode
+            # Step 2: Get the widget for the given field.
+            factory = field.widgetFactory.get(mode)
             if factory is not None:
                 widget = factory(field.field, self.request)
             else:
                 widget = zope.component.getMultiAdapter(
                     (field.field, self.request), interfaces.IFieldWidget)
-            # Step 2: Set the prefix for the widget
+            # Step 3: Set the prefix for the widget
             shortName = field.__name__
             widget.name = prefix + shortName
             widget.id = (prefix + shortName).replace('.', '-')
-            # Step 3: Set the context
+            # Step 4: Set the context
             widget.context = self.content
             zope.interface.alsoProvides(widget, interfaces.IContextAware)
-            # Step 4: Set the form
+            # Step 5: Set the form
             widget.form = self.form
             zope.interface.alsoProvides(widget, interfaces.IFormAware)
-            # Step 5: Set some variables
+            # Step 6: Set some variables
             widget.ignoreContext = self.ignoreContext
             widget.ignoreRequest = self.ignoreRequest
-            # Step 6: Set the mode of the widget
-            widget.mode = self.mode
-            # Step 7: Update the widget
+            # Step 7: Set the mode of the widget
+            widget.mode = mode
+            # Step 8: Update the widget
             widget.update()
-            # Step 8: Add the widget to the manager
+            # Step 9: Add the widget to the manager
             self._data_keys.append(shortName)
             self._data_values.append(widget)
             self._data[shortName] = widget

Modified: z3c.form/trunk/src/z3c/form/field.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/field.txt	2007-06-04 06:58:45 UTC (rev 76277)
+++ z3c.form/trunk/src/z3c/form/field.txt	2007-06-04 07:03:20 UTC (rev 76278)
@@ -452,6 +452,23 @@
   >>> manager['lastName'].mode
   'display'
 
+The exception is when some fields specifically desire a different mode. In
+this case, the last name will inherit the mode from the widget manager, while
+the first name will want to use a display wdget:
+
+  >>> addPerson.fields = field.Fields(IPerson).select('lastName')
+  >>> addPerson.fields += field.Fields(
+  ...     IPerson, mode=interfaces.DISPLAY_MODE).select('firstName')
+
+  >>> manager.mode = interfaces.INPUT_MODE
+  >>> manager.update()
+
+  >>> manager['lastName'].mode
+  'input'
+  >>> manager['firstName'].mode
+  'display'
+
+
 Besides managing widgets, the widget manager also controls the process of
 extracting and validating extracted data. Let's start with the validation
 first, which only validates the data as a whole, assuming each individual
@@ -462,6 +479,9 @@
   >>> from z3c.form import validator
   >>> zope.component.provideAdapter(validator.InvariantsValidator)
 
+  >>> addPerson.fields = field.Fields(IPerson)
+  >>> manager.update()
+
   >>> manager.validate(
   ...     {'firstName': u'Stephan', 'lastName': u'Richter'})
   ()



More information about the Checkins mailing list