[Checkins] SVN: Zope3/trunk/src/zope/app/form/ let Widget.label and Widget.hint to be written in the base implementation;

Fred L. Drake, Jr. fdrake at gmail.com
Fri Oct 20 00:25:41 EDT 2006


Log message for revision 70827:
  let Widget.label and Widget.hint to be written in the base implementation;
  the interface did not clearly specify whether these were intended to be
  read/write or read-only, so the interface makes it clear that this is
  implementation-dependent -- making the base implementation read/write
  is really just a convenience
  

Changed:
  U   Zope3/trunk/src/zope/app/form/__init__.py
  U   Zope3/trunk/src/zope/app/form/interfaces.py
  U   Zope3/trunk/src/zope/app/form/tests/test_widget.py

-=-
Modified: Zope3/trunk/src/zope/app/form/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/__init__.py	2006-10-20 03:41:16 UTC (rev 70826)
+++ Zope3/trunk/src/zope/app/form/__init__.py	2006-10-20 04:25:41 UTC (rev 70827)
@@ -18,6 +18,7 @@
 __docformat__ = 'restructuredtext'
 
 from zope.app.form.interfaces import IWidget, InputErrors
+from zope.cachedescriptors.property import readproperty
 from zope.component.interfaces import IViewFactory
 from zope.deprecation import deprecated
 from zope.interface import implements
@@ -40,10 +41,22 @@
         self.request = request
         self.name = self._prefix + context.__name__
 
-    label = property(lambda self: self.context.title)
+    @readproperty
+    def label(self):
+        """The widget label.
 
-    hint = property(lambda self: self.context.description)
+        This read-write attribute defaults to the title of the context.
+        """
+        return self.context.title
 
+    @readproperty
+    def hint(self):
+        """A hint regarding the use of the widget.
+
+        This read-write attribute defaults to the description of the context.
+        """
+        return self.context.description
+
     def _translate(self, text):
         return translate(text, context=self.request, default=text)
 

Modified: Zope3/trunk/src/zope/app/form/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/form/interfaces.py	2006-10-20 03:41:16 UTC (rev 70826)
+++ Zope3/trunk/src/zope/app/form/interfaces.py	2006-10-20 04:25:41 UTC (rev 70827)
@@ -122,16 +122,26 @@
     label = Attribute(
         """The widget label.
 
-        Label may be translated for the request.""")
+        Label may be translated for the request.
 
+        The attribute may be implemented as either a read-write or read-only
+        property, depending on the requirements for a specific implementation.
+
+        """)
+
     hint = Attribute(
         """A hint regarding the use of the widget.
 
         Hints are traditionally rendered using tooltips in GUIs, but may be
         rendered differently depending on the UI implementation.
 
-        Hint may be translated for the request.""")
+        Hint may be translated for the request.
 
+        The attribute may be implemented as either a read-write or read-only
+        property, depending on the requirements for a specific implementation.
+
+        """)
+
     visible = Attribute(
         """A flag indicating whether or not the widget is visible.""")
 

Modified: Zope3/trunk/src/zope/app/form/tests/test_widget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/tests/test_widget.py	2006-10-20 03:41:16 UTC (rev 70826)
+++ Zope3/trunk/src/zope/app/form/tests/test_widget.py	2006-10-20 04:25:41 UTC (rev 70827)
@@ -61,6 +61,18 @@
         >>> widget.visible
         True
 
+    The `label` and `hint` attributes can be overriden, allowing views to
+    change them in specific contexts without needing to affect information
+    stored in the data model (the schema):
+
+        >>> widget.label = u'My Alternate Label'
+        >>> widget.label
+        u'My Alternate Label'
+
+        >>> widget.hint = u'Better help would be good.'
+        >>> widget.hint
+        u'Better help would be good.'
+
     In the last example, the widget name consists of a prefix, a dot, and the
     field name. You can change the prefix used by the widget as follows:
 



More information about the Checkins mailing list