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

Garrett Smith garrett at mojave-corp.com
Mon Mar 1 18:34:24 EST 2004


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

Modified Files:
      Tag: garrett-widgets2-branch
	vocabularywidget.py vocabularywidget.zcml 
Log Message:
Reverted changes to vocabulary widgets re widget lookup.


=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.63.14.1 => 1.63.14.2 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.63.14.1	Thu Feb 26 00:10:49 2004
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py	Mon Mar  1 18:33:47 2004
@@ -21,7 +21,7 @@
 """
 from xml.sax.saxutils import quoteattr
 
-from zope.interface import Interface, implements, implementedBy
+from zope.interface import implements, implementedBy
 from zope.interface.declarations import directlyProvides
 from zope.publisher.browser import BrowserView
 from zope.security.proxy import trustedRemoveSecurityProxy
@@ -36,84 +36,75 @@
 from zope.app.services.servicenames import Translation
 
 
-# Marker interfaces for vocabulary widget lookup
+# These widget factories delegate to the vocabulary on the field.
 
-class IVocabularyDisplayWidget(Interface):
-    pass
-    
-class IVocabularyEditWidget(Interface):
-    pass
-    
-class IVocabularyBagDisplayWidget(Interface):
-    pass
-    
-class IVocabularyListDisplayWidget(Interface):
-    pass
-    
-class IVocabularyMultiEditWidget(Interface):
-    pass
+# Display
 
-# Marker interfaces for query view helpers
+def VocabularyFieldDisplayWidget(field, request):
+    """Return a display widget based on a vocabulary field."""
+    return _get_vocabulary_widget(field, request, "display")
 
-class IWidgetQueryHelper(Interface):
-    pass
-    
-class IWidgetQueryListHelper(Interface):
-    pass
+def VocabularyBagFieldDisplayWidget(field, request):
+    """Return a display widget based on a vocabulary field."""
+    return _get_vocabulary_widget(field, request, "display-bag")
 
-# Factory functions to create vocabulary widgets for vocab field types
- 
-def VocabularyFieldDisplayWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyDisplayWidget, request)
+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
 
 def VocabularyFieldEditWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyEditWidget, request,
-                               queryType=IWidgetQueryHelper)
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request)
 
-def VocabularyBagFieldDisplayWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyBagDisplayWidget, request)
-    
 def VocabularyBagFieldEditWidget(field, request):
-    # XXX not sure about IVocabularyMultiEditWidget - this is a guess
-    return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
-                               queryType=IWidgetQueryListHelper)
-
-def VocabularyListFieldDisplayWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyListDisplayWidget, request)
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "bag")
 
 def VocabularyListFieldEditWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
-                               queryType=IWidgetQueryListHelper)
-
-def VocabularySetFieldDisplayWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyBagDisplayWidget, request)
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "list")
 
 def VocabularySetFieldEditWidget(field, request):
-    # XXX not sure about IVocabularyMultiEditWidget - this is a guess
-    return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
-                               queryType=IWidgetQueryListHelper)
-
-def VocabularyUniqueListFieldDisplayWidget(field, request):
-    return getVocabularyWidget(field, IVocabularyListDisplayWidget, request)
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "set")
 
 def VocabularyUniqueListFieldEditWidget(field, request):
-    # XXX not sure about IVocabularyMultiEditWidget - this is a guess
-    return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
-                               queryType=IWidgetQueryListHelper)
-    
-        
-def getVocabularyWidget(field, widgetType, request, queryType=None):
-    """Returns a widget for a field vocabulary."""
-    widget = zapi.getViewProviding(field.vocabulary, widgetType, request)
-    widget.setField(field)
-    if queryType is not None:
-        query = field.vocabulary.getQuery()
-        if query is not None:
-            queryView = zapi.getViewProviding(query, queryType, request)
-            widget.setQuery(query, queryView)
-            queryView.setWidget(widget)
-    return widget
-    
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "unique-list")
+
+
+# Helper functions for the factories:
+
+def _get_vocabulary_widget(field, request, viewname):
+    view = zapi.getView(field.vocabulary,
+                        "field-%s-widget" % viewname, request)
+    view = trustedRemoveSecurityProxy(view)
+    view.setField(field)
+    return view
+
+def _get_vocabulary_edit_widget(field, request, modifier=''):
+    if modifier:
+        modifier = "-" + modifier
+    viewname = "edit" + modifier
+    view = _get_vocabulary_widget(field, request, viewname)
+    query = field.vocabulary.getQuery()
+    if query is not None:
+        queryname = "widget-query%s-helper" % modifier
+        queryview = zapi.getView(query, queryname, request)
+        view.setQuery(query, queryview)
+        queryview.setWidget(view)
+    return view
+
 
 class IterableVocabularyQuery(object):
     """Simple query object used to invoke the simple selection mechanism."""
@@ -174,8 +165,6 @@
 class VocabularyWidgetBase(ViewSupport, widget.BrowserWidget):
     """Convenience base class for vocabulary-based widgets."""
 
-    propertyNames = ["extra"]
-
     extra = ""
     type = "vocabulary"
     context = None
@@ -199,7 +188,7 @@
         self.empty_marker_name = self.name + "-empty-marker"
 
     def __call__(self):
-        if not self._renderedValueSet():
+        if self._data is self._data_marker:
             if self.hasInput():
                 try:
                     value = self.getInputValue()
@@ -320,8 +309,6 @@
 
 class VocabularyDisplayWidget(SingleDataHelper, VocabularyWidgetBase):
     """Simple single-selection display that can be used in many cases."""
-    
-    implements(IVocabularyDisplayWidget)
 
     _msg_no_value = _msg_missing_single_value_display
 
@@ -335,8 +322,6 @@
 
 class VocabularyMultiDisplayWidget(MultiDataHelper, VocabularyWidgetBase):
 
-    propertyNames = ['itemTag', 'tag']
-
     itemTag = 'li'
     tag = 'ol'
 
@@ -344,7 +329,7 @@
         if value:
             rendered_items = self.renderItems(value)
             return widget.renderElement(self.tag,
-                                        type=self.inputType,
+                                        type=self.type,
                                         name=self.name,
                                         id=self.name,
                                         cssClass=self.cssClass,
@@ -374,9 +359,6 @@
     This can be used for both VocabularyListField and
     VocabularyUniqueListField fields.
     """
-    
-    implements(IVocabularyListDisplayWidget)
-    
     tag = 'ol'
 
 
@@ -386,9 +368,6 @@
     This can be used for both VocabularyBagField and
     VocabularySetField fields.
     """
-    
-    implements(IVocabularyBagDisplayWidget)
-    
     tag = 'ul'
 
 
@@ -416,13 +395,10 @@
         return ("<input type='submit' name='%s.action-%s' value=%s %s />"
                 % (self.name, action, quoteattr(self.translate(msgid)),
                    disabled and "\n       disabled='disabled' " or ""))
-                   
-                   
+
+
 class VocabularyEditWidgetBase(VocabularyWidgetBase):
     
-    implements(IVocabularyEditWidget)
-    
-    propertyNames = ['size', 'tag']
     size = 5
     tag = 'select'
 
@@ -526,7 +502,6 @@
     to be small.
     """
     implements(implementedBy(widget.SingleItemsWidget))
-    propertyNames = ['firstItem']
     firstItem = False
 
     _msg_no_value = _msg_missing_single_value_edit
@@ -598,7 +573,6 @@
     to be very large.
     """
     implements(implementedBy(widget.SingleItemsWidget))
-    propertyNames = ['firstItem']
     firstItem = False
 
     _msg_no_value = _msg_missing_single_value_edit
@@ -641,8 +615,6 @@
 
 class VocabularyMultiEditWidget(MultiDataHelper, VocabularyEditWidgetBase):
     """Vocabulary-backed widget supporting multiple selections."""
-    
-    implements(IVocabularyMultiEditWidget)
 
     _msg_no_value = _msg_missing_multiple_value_edit
 
@@ -862,8 +834,6 @@
         return value
 
 class IterableVocabularyQueryView(IterableVocabularyQueryViewBase):
-    
-    implements(IWidgetQueryHelper)
 
     def makeSelectionList(self, items, name):
         return self.mkselectionlist("radio", items, name)
@@ -873,8 +843,6 @@
             results, [value])
 
 class IterableVocabularyQueryMultiView(IterableVocabularyQueryViewBase):
-    
-    implements(IWidgetQueryListHelper)
 
     def makeSelectionList(self, items, name):
         return self.mkselectionlist("checkbox", items, name)


=== Zope3/src/zope/app/browser/form/vocabularywidget.zcml 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.zcml:1.1.2.1	Thu Feb 26 00:10:49 2004
+++ Zope3/src/zope/app/browser/form/vocabularywidget.zcml	Mon Mar  1 18:33:47 2004
@@ -1,63 +1,81 @@
 <configure xmlns="http://namespaces.zope.org/zope">
-   
-  <!-- Vocabulary widgets -->
-  
+
+  <!-- Query view helpers -->
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
-      for="zope.schema.interfaces.IVocabulary"
-      provides=".vocabularywidget.IVocabularyDisplayWidget"
-      factory=".vocabularywidget.VocabularyDisplayWidget"      
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      allowed_interface="zope.app.interfaces.browser.form.IVocabularyQueryView"
+      for="zope.schema.interfaces.IIterableVocabularyQuery"
+      name="widget-query-helper"
+      factory=".vocabularywidget.IterableVocabularyQueryView"
       />
-	  
+
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
-      for="zope.schema.interfaces.IVocabulary"
-      provides=".vocabularywidget.IVocabularyEditWidget"
-      factory=".vocabularywidget.VocabularyEditWidget"      
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      allowed_interface="zope.app.interfaces.browser.form.IVocabularyQueryView"
+      for="zope.schema.interfaces.IIterableVocabularyQuery"
+      name="widget-query-list-helper"
+      factory=".vocabularywidget.IterableVocabularyQueryMultiView"
       />
 
+  <!-- Vocabulary field display widgets -->
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
-      for="zope.schema.interfaces.IVocabulary"
-      provides=".vocabularywidget.IVocabularyListDisplayWidget"
-      factory=".vocabularywidget.VocabularyListDisplayWidget"      
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyDisplayWidget"
+      name="field-display-widget"
+      for="zope.schema.interfaces.IVocabulary"
       />
-	  
+
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyBagDisplayWidget"
+      name="field-display-bag-widget"
       for="zope.schema.interfaces.IVocabulary"
-      provides=".vocabularywidget.IVocabularyMultiEditWidget"
-      factory=".vocabularywidget.VocabularyMultiEditWidget"      
+      />
+
+  <view
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyListDisplayWidget"
+      name="field-display-list-widget"
+      for="zope.schema.interfaces.IVocabulary"
       />
-	  
+
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyBagDisplayWidget"
+      name="field-display-set-widget"
       for="zope.schema.interfaces.IVocabulary"
-      provides=".vocabularywidget.IVocabularyBagDisplayWidget"
-      factory=".vocabularywidget.VocabularyBagDisplayWidget"      
+      />
+
+  <view
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyListDisplayWidget"
+      name="field-display-unique-list-widget"
+      for="zope.schema.interfaces.IVocabulary"
       />
-	  
-  <!-- Iterable Query Helper Views -->
-  
+
+  <!-- Vocabulary edit widgets -->
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
-      for="zope.schema.interfaces.IIterableVocabularyQuery"
-      provides=".vocabularywidget.IWidgetQueryHelper"
-      factory=".vocabularywidget.IterableVocabularyQueryView"      
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyEditWidget"
+      name="field-edit-widget"
+      for="zope.schema.interfaces.IVocabulary"
       />
-	  
+
   <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"     
-      for="zope.schema.interfaces.IIterableVocabularyQuery"
-      provides=".vocabularywidget.IWidgetQueryListHelper"
-      factory=".vocabularywidget.IterableVocabularyQueryMultiView"      
       permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      factory=".vocabularywidget.VocabularyMultiEditWidget"
+      name="field-edit-list-widget"
+      for="zope.schema.interfaces.IVocabulary"
       />
+
       
 </configure>




More information about the Zope3-Checkins mailing list