[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - vocabularywidget.py:1.30

Fred L. Drake, Jr. fred@zope.com
Tue, 3 Jun 2003 15:25:15 -0400


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

Modified Files:
	vocabularywidget.py 
Log Message:
- some minor re-organization to keep logically related things together
- getAction():  add a pre-condition to aid in debugging
- IterableVocabularyQueryViewBase:  removed default action value from
  class; it's not needed


=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.29 => 1.30 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.29	Tue Jun  3 11:14:26 2003
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py	Tue Jun  3 15:25:15 2003
@@ -36,18 +36,22 @@
 
 # These widget factories delegate to the vocabulary on the field.
 
+# Display
+
 def VocabularyFieldDisplayWidget(field, request):
     """Return a display widget based on a vocabulary field."""
     return _get_vocabulary_widget(field, request, "display")
 
-def VocabularyFieldEditWidget(field, request):
-    """Return a value-selection widget based on a vocabulary field."""
-    return _get_vocabulary_edit_widget(field, request)
-
 def VocabularyMultiFieldDisplayWidget(field, request):
     """Return a display widget based on a vocabulary field."""
     return _get_vocabulary_widget(field, request, "display-multi")
 
+# Edit
+
+def VocabularyFieldEditWidget(field, request):
+    """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")
@@ -80,10 +84,10 @@
     if modifier:
         modifier = "-" + modifier
     viewname = "edit" + modifier
-    queryname = "widget-query%s-helper" % modifier
     view = _get_vocabulary_widget(field, request, viewname)
     query = field.vocabulary.getQuery()
     if query is not None:
+        queryname = "widget-query%s-helper" % modifier
         queryview = getView(query, queryname, request)
         view.setQuery(query, queryview)
     return view
@@ -147,6 +151,12 @@
         assert field.context is not None
         self.context = field
         self.setPrefix(self._prefix)
+        assert self.name
+
+    def setPrefix(self, prefix):
+        super(VocabularyWidgetBase, self).setPrefix(prefix)
+        # names for other information from the form
+        self.empty_marker_name = self.name + "-empty-marker"
 
     def __call__(self):
         if self._data is None:
@@ -194,11 +204,6 @@
                                        self.title, str(v))
         return data
 
-    def setPrefix(self, prefix):
-        super(VocabularyWidgetBase, self).setPrefix(prefix)
-        # names for other information from the form
-        self.empty_marker_name = self.name + "-empty-marker"
-
     def _emptyMarker(self):
         return "<input name='%s' type='hidden' value='1' />" % (
             self.empty_marker_name)
@@ -314,6 +319,8 @@
         self.__actions[action] = msgid
 
     def getAction(self):
+        assert self.__actions is not None, \
+               "getAction() called on %r with no actions defined" % self
         get = self.request.form.get
         for action in self.__actions.iterkeys():
             name = "%s.action-%s" % (self.name, action)
@@ -568,8 +575,6 @@
     __implements__ = IVocabularyQueryView
 
     queryResultBatchSize = 8
-
-    action = None
 
     _msg_add_done   = _message(_("vocabulary-query-button-add-done"),
                                "Add")