[Checkins] SVN: z3c.form/trunk/ - Feature: Exposed several attributes of the widget manager to the form for

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Jul 20 22:47:02 EDT 2007


Log message for revision 78237:
  - Feature: Exposed several attributes of the widget manager to the form for
    convenience. The attributes are: mode, ignoreContext, ignoreRequest,
    ignoreReadonly.
  
  

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/interfaces.py

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2007-07-21 02:30:08 UTC (rev 78236)
+++ z3c.form/trunk/CHANGES.txt	2007-07-21 02:47:01 UTC (rev 78237)
@@ -5,6 +5,10 @@
 Version 1.6.0 (?/??/2007)
 -------------------------
 
+- Feature: Exposed several attributes of the widget manager to the form for
+  convenience. The attributes are: mode, ignoreContext, ignoreRequest,
+  ignoreReadonly.
+
 - Feature: Provide more user-friendly error messages for number formatting.
 
 

Modified: z3c.form/trunk/src/z3c/form/form.py
===================================================================
--- z3c.form/trunk/src/z3c/form/form.py	2007-07-21 02:30:08 UTC (rev 78236)
+++ z3c.form/trunk/src/z3c/form/form.py	2007-07-21 02:47:01 UTC (rev 78237)
@@ -77,6 +77,11 @@
     status = ''
     template = None
 
+    mode = interfaces.INPUT_MODE
+    ignoreContext = False
+    ignoreRequest = False
+    ignoreReadonly = False
+
     def getContent(self):
         '''See interfaces.IForm'''
         return self.context
@@ -85,6 +90,10 @@
         '''See interfaces.IForm'''
         self.widgets = zope.component.getMultiAdapter(
             (self, self.request, self.getContent()), interfaces.IWidgets)
+        self.widgets.mode = self.mode
+        self.widgets.ignoreContext = self.ignoreContext
+        self.widgets.ignoreRequest = self.ignoreRequest
+        self.widgets.ignoreReadonly = self.ignoreReadonly
         self.widgets.update()
 
     def extractData(self):
@@ -107,12 +116,8 @@
 
 class DisplayForm(BaseForm):
 
-    def updateWidgets(self):
-        self.widgets = zope.component.getMultiAdapter(
-            (self, self.request, self.getContent()), interfaces.IWidgets)
-        self.widgets.mode = interfaces.DISPLAY_MODE
-        self.widgets.ignoreRequest = True
-        self.widgets.update()
+    mode = interfaces.DISPLAY_MODE
+    ignoreRequest = True
 
 
 class Form(BaseForm):
@@ -158,6 +163,9 @@
     """A field and button based add form."""
     zope.interface.implements(interfaces.IAddForm)
 
+    ignoreContext = True
+    ignoreReadonly = True
+
     _finishedAdd = False
     formErrorsMessage = _('There were some errors.')
 
@@ -172,13 +180,6 @@
         self.add(obj)
         self._finishedAdd = True
 
-    def updateWidgets(self):
-        self.widgets = zope.component.getMultiAdapter(
-            (self, self.request, self.getContent()), interfaces.IWidgets)
-        self.widgets.ignoreContext = True
-        self.widgets.ignoreReadonly = True
-        self.widgets.update()
-
     def create(self, data):
         raise NotImplementedError
 
@@ -203,11 +204,6 @@
     successMessage = _('Data successfully updated.')
     noChangesMessage = _('No changes were applied.')
 
-    def updateWidgets(self):
-        self.widgets = zope.component.getMultiAdapter(
-            (self, self.request, self.getContent()), interfaces.IWidgets)
-        self.widgets.update()
-
     def applyChanges(self, data):
         content = self.getContent()
         changed = applyChanges(self, content, data)

Modified: z3c.form/trunk/src/z3c/form/form.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/form.txt	2007-07-21 02:30:08 UTC (rev 78236)
+++ z3c.form/trunk/src/z3c/form/form.txt	2007-07-21 02:47:01 UTC (rev 78237)
@@ -1005,6 +1005,56 @@
   </html>
 
 
+Simple Form Customization
+-------------------------
+
+The form exposes several of the widget manager's attributes as attributes on
+the form. They are: ``mode``, ``ignoreContext``, ``ignoreRequest``, and
+``ignoreReadonly``.
+
+Here are the values for the display form we just created:
+
+  >>> display.mode
+  'display'
+  >>> display.ignoreContext
+  False
+  >>> display.ignoreRequest
+  True
+  >>> display.ignoreReadonly
+  False
+
+These values should be equal to the ones of the widget manager:
+
+  >>> display.widgets.mode
+  'display'
+  >>> display.widgets.ignoreContext
+  False
+  >>> display.widgets.ignoreRequest
+  True
+  >>> display.widgets.ignoreReadonly
+  False
+
+Now, if we change those values before updating the widgets, ...
+
+  >>> display.mode = interfaces.INPUT_MODE
+  >>> display.ignoreContext = True
+  >>> display.ignoreRequest = False
+  >>> display.ignoreReadonly = True
+
+... the widget manager will have the same values after updating the widgets:
+
+  >>> display.updateWidgets()
+
+  >>> display.widgets.mode
+  'input'
+  >>> display.widgets.ignoreContext
+  True
+  >>> display.widgets.ignoreRequest
+  False
+  >>> display.widgets.ignoreReadonly
+  True
+
+
 Extending Forms
 ---------------
 

Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py	2007-07-21 02:30:08 UTC (rev 78236)
+++ z3c.form/trunk/src/z3c/form/interfaces.py	2007-07-21 02:47:01 UTC (rev 78237)
@@ -136,7 +136,6 @@
 class IField(zope.interface.Interface):
     """Field wrapping a schema field used in the form."""
 
-    # TODO: define this fields
     __name__ = zope.schema.TextLine(
         title=_('Title'),
         description=_('The name of the field within the form.'),
@@ -147,13 +146,26 @@
         description=_('The schema field that is to be rendered.'),
         required=True)
 
-    prefix = zope.schema.Field()
+    prefix = zope.schema.Field(
+        title=_('Prefix'),
+        description=_('The prefix of the field used to avoid name clashes.'),
+        required=True)
 
-    mode = zope.schema.Field()
+    mode = zope.schema.Field(
+        title=_('Mode'),
+        description=_('The mode in which to render the widget for the field.'),
+        required=True)
 
-    interface = zope.schema.Field()
+    interface = zope.schema.Field(
+        title=_('Interface'),
+        description=_('The interface from which the field is coming.'),
+        required=True)
 
-    dataProvider = zope.schema.Field()
+    dataProvider = zope.schema.Field(
+        title=_('Data Provider'),
+        description=_('The component providing the data of the field for '
+                      'the widget.'),
+        required=True)
 
     widgetFactory = zope.schema.Field(
         title=_('Widget Factory'),
@@ -442,14 +454,20 @@
         title=_('Ignore Context'),
         description=_('If set the context is ignored to retrieve a value.'),
         default=False,
-        required=False)
+        required=True)
 
     ignoreRequest = zope.schema.Bool(
         title=_('Ignore Request'),
         description=_('If set the request is ignored to retrieve a value.'),
         default=False,
-        required=False)
+        required=True)
 
+    ignoreReadonly = zope.schema.Bool(
+        title=_('Ignore Readonly'),
+        description=_('If set then readonly fields will also be shown.'),
+        default=False,
+        required=True)
+
     def update():
         """Setup widgets."""
 
@@ -606,6 +624,29 @@
 class IForm(zope.interface.Interface):
     """Form"""
 
+    mode = zope.schema.Field(
+        title=_('Mode'),
+        description=_('The mode in which to render the widgets.'),
+        required=True)
+
+    ignoreContext = zope.schema.Bool(
+        title=_('Ignore Context'),
+        description=_('If set the context is ignored to retrieve a value.'),
+        default=False,
+        required=True)
+
+    ignoreRequest = zope.schema.Bool(
+        title=_('Ignore Request'),
+        description=_('If set the request is ignored to retrieve a value.'),
+        default=False,
+        required=True)
+
+    ignoreReadonly = zope.schema.Bool(
+        title=_('Ignore Readonly'),
+        description=_('If set then readonly fields will also be shown.'),
+        default=False,
+        required=True)
+
     widgets = zope.schema.Object(
         title=_('Widgets'),
         description=_('A widget manager containing the widgets to be used in '



More information about the Checkins mailing list