[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - configure.zcml:1.13 vocabularywidget.py:1.33

Fred L. Drake, Jr. fred@zope.com
Fri, 6 Jun 2003 15:25:02 -0400


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

Modified Files:
	configure.zcml vocabularywidget.py 
Log Message:
Lots of cleanup.  Remove all use of the vocabulary "multi" field;
that should only be used as a base for concrete types.

Allow the single-selection display widget to deal with missing values.


=== Zope3/src/zope/app/browser/form/configure.zcml 1.12 => 1.13 ===
--- Zope3/src/zope/app/browser/form/configure.zcml:1.12	Fri May 30 02:10:57 2003
+++ Zope3/src/zope/app/browser/form/configure.zcml	Fri Jun  6 15:24:30 2003
@@ -131,7 +131,7 @@
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
       for="zope.schema.vocabulary.IVocabularyBagField"
       name="display"
-      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      factory=".vocabularywidget.VocabularyBagFieldDisplayWidget"
       />
 
   <view
@@ -150,7 +150,7 @@
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
       for="zope.schema.vocabulary.IVocabularyListField"
       name="display"
-      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      factory=".vocabularywidget.VocabularyListFieldDisplayWidget"
       />
 
   <view
@@ -169,7 +169,7 @@
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
       for="zope.schema.vocabulary.IVocabularySetField"
       name="display"
-      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      factory=".vocabularywidget.VocabularySetFieldDisplayWidget"
       />
 
   <view
@@ -188,7 +188,7 @@
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
       for="zope.schema.vocabulary.IVocabularyUniqueListField"
       name="display"
-      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      factory=".vocabularywidget.VocabularyUniqueListFieldDisplayWidget"
       />
 
   <view


=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.32 => 1.33 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.32	Thu Jun  5 12:23:48 2003
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py	Fri Jun  6 15:24:30 2003
@@ -41,9 +41,21 @@
     """Return a display widget based on a vocabulary field."""
     return _get_vocabulary_widget(field, request, "display")
 
-def VocabularyMultiFieldDisplayWidget(field, request):
+def VocabularyBagFieldDisplayWidget(field, request):
     """Return a display widget based on a vocabulary field."""
-    return _get_vocabulary_widget(field, request, "display-multi")
+    return _get_vocabulary_widget(field, request, "display-bag")
+
+def VocabularyListFieldDisplayWidget(field, request):
+    """Return a display widget based on a vocabulary field."""
+    return _get_vocabulary_widget(field, request, "display-list")
+
+def VocabularySetFieldDisplayWidget(field, request):
+    """Return a display widget based on a vocabulary field."""
+    return _get_vocabulary_widget(field, request, "display-set")
+
+def VocabularyUniqueListFieldDisplayWidget(field, request):
+    """Return a display widget based on a vocabulary field."""
+    return _get_vocabulary_widget(field, request, "display-unique-list")
 
 # Edit
 
@@ -51,10 +63,6 @@
     """Return a value-selection widget based on a vocabulary field."""
     return _get_vocabulary_edit_widget(field, request)
 
-def VocabularyMultiFieldEditWidget(field, request):
-    """Return a value-selection widget based on a vocabulary field."""
-    return _get_vocabulary_edit_widget(field, request, "multi")
-
 def VocabularyBagFieldEditWidget(field, request):
     """Return a value-selection widget based on a vocabulary field."""
     return _get_vocabulary_edit_widget(field, request, "bag")
@@ -101,9 +109,16 @@
         self.vocabulary = vocabulary
 
 
+class TranslationHook:
+
+    def translate(self, msgid):
+        # XXX This is where we should be calling on the translation service
+        return msgid.default
+
+
 # Widget implementation:
 
-class ViewSupport(object):
+class ViewSupport(object, TranslationHook):
     """Helper class for vocabulary and vocabulary-query widgets."""
 
     def textForValue(self, term):
@@ -261,8 +276,11 @@
     """Simple single-selection display that can be used in many cases."""
 
     def render(self, value):
-        term = self.context.vocabulary.getTerm(value)
-        return self.textForValue(term)
+        if value is None:
+            return "(no value)"
+        else:
+            term = self.context.vocabulary.getTerm(value)
+            return self.textForValue(term)
 
 
 class VocabularyMultiDisplayWidget(MultiDataHelper, VocabularyWidgetBase):
@@ -307,7 +325,25 @@
         return L
 
 
-class ActionHelper(object):
+class VocabularyListDisplayWidget(VocabularyMultiDisplayWidget):
+    """Display widget for ordered multi-selection fields.
+
+    This can be used for both VocabularyListField and
+    VocabularyUniqueListField fields.
+    """
+    tag = 'ol'
+
+
+class VocabularyBagDisplayWidget(VocabularyMultiDisplayWidget):
+    """Display widget for unordered multi-selection fields.
+
+    This can be used for both VocabularyBagField and
+    VocabularySetField fields.
+    """
+    tag = 'ul'
+
+
+class ActionHelper(object, TranslationHook):
     __actions = None
 
     def addAction(self, action, msgid):
@@ -332,10 +368,6 @@
                 % (self.name, action, quoteattr(self.translate(msgid)),
                    disabled and "disabled " or ""))
 
-    def translate(self, msgid):
-        # XXX This is where we should be calling on the translation service
-        return msgid.default
-
 
 class VocabularyEditWidgetBase(VocabularyWidgetBase):
     propertyNames = (VocabularyWidgetBase.propertyNames
@@ -557,7 +589,7 @@
 ADD_MORE = "addmore"
 MORE = "more"
 
-def _message(msgid, default):
+def message(msgid, default):
     msgid.default = default
     return msgid
 
@@ -574,16 +606,16 @@
 
     queryResultBatchSize = 8
 
-    _msg_add_done   = _message(_("vocabulary-query-button-add-done"),
-                               "Add")
-    _msg_add_more   = _message(_("vocabulary-query-button-add-more"),
-                               "Add+More")
-    _msg_more       = _message(_("vocabulary-query-button-more"),
-                               "More")
-    _msg_no_results = _message(_("vocabulary-query-message-no-results"),
-                               "No Results")
-    _msg_results_header = _message(_("vocabulary-query-header-results"),
-                                  "Search results")
+    _msg_add_done   = message(_("vocabulary-query-button-add-done"),
+                              "Add")
+    _msg_add_more   = message(_("vocabulary-query-button-add-more"),
+                              "Add+More")
+    _msg_more       = message(_("vocabulary-query-button-more"),
+                              "More")
+    _msg_no_results = message(_("vocabulary-query-message-no-results"),
+                              "No Results")
+    _msg_results_header = message(_("vocabulary-query-header-results"),
+                                 "Search results")
 
     def setName(self, name):
         VocabularyQueryViewBase.setName(self, name)