[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - widget.py:1.55

Gary Poster gary at zope.com
Fri Sep 26 15:54:04 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv11773/browser/form

Modified Files:
	widget.py 
Log Message:
make title and description properties that translate themselves if possible.  Add description attribute to IWidget.



=== Zope3/src/zope/app/browser/form/widget.py 1.54 => 1.55 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.54	Thu Sep 25 17:43:12 2003
+++ Zope3/src/zope/app/browser/form/widget.py	Fri Sep 26 15:53:33 2003
@@ -43,7 +43,27 @@
 class BrowserWidget(Widget, BrowserView):
     """A field widget that knows how to display itself as HTML.
 
+    When we generate labels, titles, descriptions, and errors, the
+    labels, titles, and descriptions are translated and the
+    errors are rendered with the view machinery, so we need to set up
+    a lot of machinery to support translation and views:
+
+    >>> setUp() # now we have to set up an error view...
+    >>> from zope.component.view import provideView
+    >>> from zope.app.interfaces.form import IWidgetInputError
+    >>> from zope.publisher.browser import IBrowserPresentation
+    >>> from zope.app.publisher.browser import BrowserView
+    >>> from cgi import escape
+    >>> class SnippetErrorView(BrowserView):
+    ...     def __call__(self):
+    ...         return escape(self.context.errors[0])
+    ...
+    >>> provideView(IWidgetInputError, 'snippet',
+    ...             IBrowserPresentation, SnippetErrorView)
     >>> from zope.publisher.browser import TestRequest
+
+    And now the tests proper...
+
     >>> from zope.schema import Field
     >>> import re
     >>> isFriendly=re.compile(".*hello.*").match
@@ -74,22 +94,6 @@
     >>> widget.error()
     ''
 
-    When we generate labels and errors, the labels are translated and the 
-    errors rendered with the view machinery, so we need to set up
-    a lot of machinery to support translation and views:
-
-    >>> setUp() # now we have to set up an error view...
-    >>> from zope.component.view import provideView
-    >>> from zope.app.interfaces.form import IWidgetInputError
-    >>> from zope.publisher.browser import IBrowserPresentation
-    >>> from zope.app.publisher.browser import BrowserView
-    >>> from cgi import escape
-    >>> class SnippetErrorView(BrowserView):
-    ...     def __call__(self):
-    ...         return escape(self.context.errors[0])
-    ... 
-    >>> provideView(IWidgetInputError, 'snippet', 
-    ...             IBrowserPresentation, SnippetErrorView)
     >>> widget.setPrefix('baz')
     >>> widget.name
     'baz.foo'
@@ -127,9 +131,12 @@
     1
     >>> widget.error()
     ''
-    
+
     >>> print widget.label()
     <label for="test.foo">Foo</label>
+
+    Now we clean up.
+
     >>> tearDown()
 
     """
@@ -158,7 +165,7 @@
 
     def hasInput(self):
         """See IWidget.hasInput.
-        
+
         Returns True if the submitted request form contains a value for
         the widget, otherwise returns False.
 
@@ -225,7 +232,7 @@
 
     def _convert(self, input):
         """Converts input to a value appropriate for the field type.
-        
+
         Widgets for non-string fields should override this method to
         perform an appropriate conversion.
 
@@ -316,16 +323,10 @@
             return txt
 
     def label(self):
-        ts = getService(self.context, Translation)
-        # Note that the domain is not that important here, since the title
-        # is most likely a message id carrying the domain anyways.
-        title = ts.translate(self.title, "zope", context=self.request)
-        if title is None:
-            title = self.title
         return '<label for="%s">%s</label>' % (
-            self.name, self._tooltip(title, self.context.description),
-            )
-    
+            self.name, self._tooltip(self.title,
+                                     self.context.description))
+
     def error(self):
         if self._error:
             return zapi.getView(self._error, 'snippet', self.request)()
@@ -338,7 +339,7 @@
         if self._error:
             return '<div class="%s">%s</div><div class="field">%s</div>' \
                 '<div class="error">%s</div>' % (self.labelClass(),
-                                                 self.label(), self(), 
+                                                 self.label(), self(),
                                                  self.error())
         else:
             return '<div class="%s">%s</div><div class="field">%s</div>' % (
@@ -393,7 +394,7 @@
       />
 
     Calling setRenderedValue will change what gets output:
-    
+
     >>> widget.setRenderedValue(False)
     >>> print normalize( widget() )
     <input
@@ -496,7 +497,7 @@
       />
 
     Calling setRenderedValue will change what gets output:
-    
+
     >>> widget.setRenderedValue("Barry")
     >>> print normalize( widget() )
     <input
@@ -527,7 +528,7 @@
         if field.allowed_values is not None:
             values = []
             # if field is optional and missing_value isn't in
-            # allowed_values, add an additional option at top to represent 
+            # allowed_values, add an additional option at top to represent
             # field.missing_value
             if not field.required and \
                 field.missing_value not in field.allowed_values:
@@ -655,7 +656,7 @@
                 return parseDatetimetz(value).date()
             except (DateTimeError, ValueError, IndexError), v:
                 raise ConversionError("Invalid datetime data", v)
-                
+
 
 class TextAreaWidget(BrowserWidget):
     """TextArea widget.
@@ -695,7 +696,7 @@
       />
 
     Calling setRenderedValue will change what gets output:
-    
+
     >>> widget.setRenderedValue("Hey\\ndude!")
     >>> print normalize( widget() )
     <textarea




More information about the Zope3-Checkins mailing list