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

Fred L. Drake, Jr. fred@zope.com
Fri, 30 May 2003 02:11:28 -0400


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

Modified Files:
	configure.zcml vocabularywidget.py 
Log Message:
Refactoring of the multi-select vocabulary field:
- define 4 concrete types covering uniqueness constraints (whether a value
  may appear multiple times) and ordering support (whether theres

=== Zope3/src/zope/app/browser/form/configure.zcml 1.11 => 1.12 ===
--- Zope3/src/zope/app/browser/form/configure.zcml:1.11	Thu May 29 10:33:02 2003
+++ Zope3/src/zope/app/browser/form/configure.zcml	Fri May 30 02:10:57 2003
@@ -104,6 +104,8 @@
 
   <!-- Vocabulary fields share special widget factories that redirect
        to the vocabularies they reference. -->
+
+  <!-- Single selection -->
   <view
       permission="zope.Public"
       type="zope.publisher.interfaces.browser.IBrowserPresentation"
@@ -122,11 +124,69 @@
       factory=".vocabularywidget.VocabularyFieldEditWidget"
       />
 
+  <!-- Bags -->
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularyBagField"
+      name="display"
+      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      />
+
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularyBagField"
+      name="edit"
+      factory=".vocabularywidget.VocabularyBagFieldEditWidget"
+      />
+
+  <!-- Lists -->
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularyListField"
+      name="display"
+      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      />
+
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularyListField"
+      name="edit"
+      factory=".vocabularywidget.VocabularyListFieldEditWidget"
+      />
+
+  <!-- Sets -->
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularySetField"
+      name="display"
+      factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
+      />
+
+  <view
+      permission="zope.Public"
+      type="zope.publisher.interfaces.browser.IBrowserPresentation"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.vocabulary.IVocabularySetField"
+      name="edit"
+      factory=".vocabularywidget.VocabularySetFieldEditWidget"
+      />
+
+  <!-- Unique lists -->
   <view
       permission="zope.Public"
       type="zope.publisher.interfaces.browser.IBrowserPresentation"
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
-      for="zope.schema.vocabulary.IVocabularyMultiField"
+      for="zope.schema.vocabulary.IVocabularyUniqueListField"
       name="display"
       factory=".vocabularywidget.VocabularyMultiFieldDisplayWidget"
       />
@@ -135,11 +195,12 @@
       permission="zope.Public"
       type="zope.publisher.interfaces.browser.IBrowserPresentation"
       allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
-      for="zope.schema.vocabulary.IVocabularyMultiField"
+      for="zope.schema.vocabulary.IVocabularyUniqueListField"
       name="edit"
-      factory=".vocabularywidget.VocabularyMultiFieldEditWidget"
+      factory=".vocabularywidget.VocabularyUniqueListFieldEditWidget"
       />
 
+  <!-- Query view helpers -->
   <view
       permission="zope.Public"
       type="zope.publisher.interfaces.browser.IBrowserPresentation"


=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.16	Thu May 29 18:25:20 2003
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py	Fri May 30 02:10:57 2003
@@ -41,7 +41,7 @@
 
 def VocabularyFieldEditWidget(field, request):
     """Return a value-selection widget based on a vocabulary field."""
-    return _get_vocabulary_edit_widget(field, request, ismulti=False)
+    return _get_vocabulary_edit_widget(field, request)
 
 def VocabularyMultiFieldDisplayWidget(field, request):
     """Return a display widget based on a vocabulary field."""
@@ -49,7 +49,23 @@
 
 def VocabularyMultiFieldEditWidget(field, request):
     """Return a value-selection widget based on a vocabulary field."""
-    return _get_vocabulary_edit_widget(field, request, ismulti=True)
+    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")
+
+def VocabularyListFieldEditWidget(field, request):
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "list")
+
+def VocabularySetFieldEditWidget(field, request):
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "set")
+
+def VocabularyUniqueListFieldEditWidget(field, request):
+    """Return a value-selection widget based on a vocabulary field."""
+    return _get_vocabulary_edit_widget(field, request, "unique-list")
 
 
 # Helper functions for the factories:
@@ -59,13 +75,11 @@
     view.setField(field)
     return view
 
-def _get_vocabulary_edit_widget(field, request, ismulti):
-    if ismulti:
-        viewname = "edit-multi"
-        queryname = "widget-query-multi-helper"
-    else:
-        viewname = "edit"
-        queryname = "widget-query-helper"
+def _get_vocabulary_edit_widget(field, request, modifier=''):
+    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: