[Zope3-checkins] SVN: Zope3/trunk/src/ Merged from ZopeX3-3.0 branch:

Jim Fulton jim at zope.com
Fri Oct 1 14:22:46 EDT 2004


Log message for revision 27731:
  Merged from ZopeX3-3.0 branch:
  
    r27726 | jim | 2004-09-30 19:00:04 -0400 (Thu, 30 Sep 2004) | 6 lines
  
    Removed the non-functional vocabulary query support.
  
    We'll add this back later in some form, when we have
    time to get it right and to document it enough so 
    that it is maintainable.
  
  (Also made some declarations for software on the trunk
  and not on the branch.)
  
  


Changed:
  U   Zope3/trunk/src/bugtracker/configure.zcml
  D   Zope3/trunk/src/zope/app/form/browser/complexsample/
  U   Zope3/trunk/src/zope/app/form/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/form/browser/interfaces.py
  U   Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
  U   Zope3/trunk/src/zope/app/form/browser/tests/test_registrations.py
  D   Zope3/trunk/src/zope/app/form/browser/tests/test_vocabularyquery.py
  D   Zope3/trunk/src/zope/app/form/browser/vocabularyquery.py
  U   Zope3/trunk/src/zope/app/renderer/tests/test_vocabulary.py
  U   Zope3/trunk/src/zope/app/schema/fields.zcml
  U   Zope3/trunk/src/zope/app/utility/vocabulary.py
  U   Zope3/trunk/src/zope/app/workflow/configure.zcml
  U   Zope3/trunk/src/zope/schema/interfaces.py
  U   Zope3/trunk/src/zope/schema/tests/states.py
  D   Zope3/trunk/src/zope/schema/tests/tabcomplete.py
  D   Zope3/trunk/src/zope/schema/tests/test_tabcomplete.py
  U   Zope3/trunk/src/zope/schema/tests/test_vocabulary.py
  U   Zope3/trunk/src/zope/schema/vocabulary.py


-=-
Modified: Zope3/trunk/src/bugtracker/configure.zcml
===================================================================
--- Zope3/trunk/src/bugtracker/configure.zcml	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/bugtracker/configure.zcml	2004-10-01 18:22:45 UTC (rev 27731)
@@ -110,7 +110,6 @@
      factory=".vocabulary.UserVocabulary" />
 
   <content class=".vocabulary.ManagableVocabulary">
-    <allow interface="zope.schema.interfaces.IVocabulary"/>
     <allow interface="zope.schema.interfaces.IVocabularyTokenized"/>
     <allow attributes="default title"/>
     <require
@@ -141,7 +140,6 @@
   </content>
 
   <content class=".vocabulary.UserVocabulary">
-    <allow interface="zope.schema.interfaces.IVocabulary"/>
     <allow interface="zope.schema.interfaces.IVocabularyTokenized"/>
   </content>
 

Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-10-01 18:22:45 UTC (rev 27731)
@@ -270,7 +270,7 @@
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="zope.schema.interfaces.IChoice
-           zope.schema.interfaces.IIterableVocabulary"
+           zope.schema.interfaces.IVocabularyTokenized"
       provides="zope.app.form.interfaces.IDisplayWidget"
       factory=".ItemDisplayWidget"
       permission="zope.Public"
@@ -279,7 +279,7 @@
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="zope.schema.interfaces.IChoice
-           zope.schema.interfaces.IIterableVocabulary"
+           zope.schema.interfaces.IVocabularyTokenized"
       provides="zope.app.form.interfaces.IInputWidget"
       factory=".DropdownWidget"
       permission="zope.Public"
@@ -290,7 +290,7 @@
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="zope.schema.interfaces.IList
-           zope.schema.interfaces.IIterableVocabulary"
+           zope.schema.interfaces.IVocabularyTokenized"
       provides="zope.app.form.interfaces.IInputWidget"
       factory=".MultiSelectWidget"
       permission="zope.Public"
@@ -299,30 +299,10 @@
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="zope.schema.interfaces.IList
-           zope.schema.interfaces.IIterableVocabulary"
+           zope.schema.interfaces.IVocabularyTokenized"
       provides="zope.app.form.interfaces.IDisplayWidget"
       factory=".SetDisplayWidget"
       permission="zope.Public"
       />
 
-  <!-- Register a couple of default vocabulary query views. -->
-
-  <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IVocabularyQuery
-           zope.schema.interfaces.IChoice"
-      provides="zope.app.form.browser.interfaces.IVocabularyQueryView"
-      factory=".vocabularyquery.IterableVocabularyQueryView"
-      permission="zope.Public"
-      />
-
-  <view
-      type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IVocabularyQuery
-           zope.schema.interfaces.ICollection"
-      provides="zope.app.form.browser.interfaces.IVocabularyQueryView"
-      factory=".vocabularyquery.IterableVocabularyQueryMultiView"
-      permission="zope.Public"
-      />
-
 </configure>

Modified: Zope3/trunk/src/zope/app/form/browser/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/interfaces.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/interfaces.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -151,62 +151,7 @@
         The default implementation returns `self.context.nextURL()`,
         i.e. it delegates to the `IAdding` view.
         """
-class IVocabularyQueryView(Interface):
-    """View support for `IVocabularyQuery` objects.
 
-    Implementations of this interface are used by vocabulary field
-    edit widgets to support query and result presentations.
-    """
-
-    def __init__(query, field, request):
-        """This is a multiview, which is looked up for (query, field) pairs."""
-
-    def setName(name):
-        """Set the name used to compute the form field names.
-
-        Form field names should be the given name, or additional name
-        components separated by dots may be appended if multiple form
-        fields are needed.
-
-        This method will be called after the `IVocabularyQueryView` has
-        been created and before `performAction()` is called.
-        """
-
-
-    def setWidget(widget):
-        """Set the widget using this query view.
-
-        This allows the query view to take advantage of rendering
-        helper methods made available by the widget.
-
-        This method will be called after the `IVocabularyQueryView` has
-        been created and before `performAction()` is called.
-        """
-
-    def performAction(value):
-        """Perform any action indicated by any submit buttons in the
-        sub-widget.
-
-        `value` is the current value of the field.  Submit actions may
-        cause the value to be modified.  If so, the new value should
-        be returned; otherwise the old value should be returned.
-
-        Actions should only be performed if a submit button provided
-        by the view was selected.
-
-        This method will be called after `setName()` and `setWidget()` and
-        before `renderInput()` or `renderResults()`.
-        """
-
-    def renderInput():
-        """Return a rendering of the input portion of the widget."""
-
-    def renderResults(value):
-        """Return a rendering of the results portion of the widget.
-
-        `value` is the current value represented by the widget.
-        """
-
 class IWidgetInputErrorView(Interface):
     """Display an input error as a snippet of text."""
 

Modified: Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -25,7 +25,6 @@
 
 from zope.app import zapi
 from zope.app.form.browser.widget import SimpleInputWidget, renderElement
-from zope.app.form.browser.interfaces import IVocabularyQueryView
 from zope.app.form.interfaces import IInputWidget, IDisplayWidget
 from zope.app.form.interfaces import ConversionError
 
@@ -287,20 +286,6 @@
         """Initialize the widget."""
         super(ItemsEditWidgetBase, self).__init__(field, vocabulary, request)
 
-        # Queries are used in items widgets to reduce the amount of choices,
-        # since some vocabularies could literally provide an infinite number
-        # of terms.
-        self.queryview = None
-        query = vocabulary.getQuery()
-        if query is not None:
-            view = zapi.queryMultiView((query, field), request,
-                                       IVocabularyQueryView)
-            if view is not None:
-                self.queryview = view
-                self.queryview.setWidget(self)
-                self.queryview.setName(self.name + "-query")
-
-
     def setPrefix(self, prefix):
         """Set the prefix of the input name.
 
@@ -308,8 +293,6 @@
         field and the postfix '-query' for the associated query view.
         """
         super(ItemsEditWidgetBase, self).setPrefix(prefix)
-        if self.queryview is not None:
-            self.queryview.setName(self.name + "-query")
 
 
     def __call__(self):
@@ -318,23 +301,9 @@
         contents = []
         have_results = False
 
-        # If a query view was specified, provide the necessary UI
-        if self.queryview is not None:
-            html = self.queryview.renderResults(value)
-            if html:
-                contents.append(self._div('queryresults', html))
-                html = self.queryview.renderInput()
-                contents.append(self._div('queryinput', html))
-                have_results = True
-
         contents.append(self._div('value', self.renderValue(value)))
         contents.append(self._emptyMarker())
 
-        if self.queryview is not None and not have_results:
-            html = self.queryview.renderInput()
-            if html:
-                contents.append(self._div('queryinput', html))
-
         return self._div(self.cssClass, "\n".join(contents),
                          id=self.name)
 

Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_registrations.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_registrations.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_registrations.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -41,19 +41,12 @@
 class SampleObject(object):
     implements(ISampleObject)
 
-class ISampleVocabulary(
-    interfaces.IVocabularyTokenized, interfaces.IVocabulary):
+class ISampleVocabulary(interfaces.IVocabularyTokenized,
+                        interfaces.IVocabulary):
     pass
 
-class SampleVocabularyQuery(object):
-    implements(interfaces.IIterableVocabularyQuery)
-    def __init__(self, vocabulary):
-        self.vocabulary = vocabulary    
-
 class SampleVocabulary(vocabulary.SimpleVocabulary):
     implements(ISampleVocabulary)
-    def getQuery(self):
-        return SampleVocabularyQuery(self)
 
 request = TestRequest()
 sample = SampleObject()

Deleted: Zope3/trunk/src/zope/app/form/browser/tests/test_vocabularyquery.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_vocabularyquery.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_vocabularyquery.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -1,204 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Tests of the vocabulary queries.
-
-$Id$
-"""
-import unittest
-from zope.interface import implements
-from zope.publisher.browser import TestRequest
-from zope.publisher.browser import IBrowserRequest
-from zope.schema import vocabulary, Choice, List
-from zope.schema.interfaces import IVocabularyQuery, IChoice, ICollection
-
-from zope.app import zapi
-from zope.app.tests import ztapi
-from zope.app.tests.placelesssetup import PlacelessSetup
-
-from zope.app.form.browser import DropdownWidget, MultiSelectWidget
-from zope.app.form.browser.interfaces import IVocabularyQueryView
-from zope.app.form.browser.vocabularyquery import VocabularyQueryViewBase
-from zope.app.form.browser.tests import support
-
-_marker = object()
-
-class SampleContent(object):
-    """Stub content object used by makeField()."""
-    def __init__(self, value):
-        self.f = value
-
-
-class SampleQueryVocabulary(vocabulary.SimpleVocabulary):
-    """Vocabulary that offer simple query support."""
-
-    def getQuery(self):
-        return SampleVocabularyQuery(self)
-
-
-class ISampleVocabularyQuery(IVocabularyQuery):
-    """Specialized query type."""
-
-
-class SampleVocabularyQuery(object):
-    """Vocabulary query object which query views can be registered for."""
-
-    implements(ISampleVocabularyQuery)
-
-    def __init__(self, vocabulary):
-        self.vocabulary = vocabulary
-
-
-class SampleQueryViewSingle(VocabularyQueryViewBase):
-    """Single-selection vocabulary query view."""
-
-    implements(IVocabularyQueryView)
-
-    label = "single"
-
-    def _getResults(self):
-        return self.request.form.get(self.name)
-
-    def _renderQueryInput(self):
-        return "this-is-query-input"
-
-    def _renderQueryResults(self, results, value):
-        return "query-results-go-here"
-
-
-class SampleQueryViewMulti(SampleQueryViewSingle):
-    """Multi-selection vocabulary query view."""
-
-    label = "multi"
-
-
-class QuerySupportTestBase(PlacelessSetup,
-                           support.VerifyResults,
-                           unittest.TestCase):
-    """Base class defining tests that can be used for both single- and
-    multi-select query support.
-
-    Derived classes must specialize to support specific selection
-    mechanics.
-    """
-    _marker = object()
-    defaultFieldValue = None
-
-    _sampleVocabulary = SampleQueryVocabulary.fromValues(
-        ["splat", "foobar", "frob"])
-    _widgetFactory = None
-
-    def setUp(self):
-        super(QuerySupportTestBase, self).setUp()
-        self.registerViews()
-
-    def _makeWidget(self, form={}):
-        vocab = self._sampleVocabulary
-        bound = self.makeField(vocabulary=vocab)
-        widget = self._widgetFactory(bound, vocab, TestRequest(form=form))
-        return widget
-
-    def test_get_query_helper(self):
-        widget = self._makeWidget()
-        self.assert_(
-            isinstance(widget.queryview.context, SampleVocabularyQuery))
-        self.assert_(widget.queryview.widget is widget)
-        self.assertEqual(widget.queryview.name, widget.name + "-query")
-        self.assertEqual(widget.queryview.label, self.queryViewLabel)
-
-    def test_query_input_section(self):
-        widget = self._makeWidget()
-        widget.setRenderedValue(self.defaultFieldValue)
-        checks = [
-            "this-is-query-input",
-            ]
-        self.verifyResult(widget.queryview.renderInput(), checks)
-        self.verifyResult(widget(), checks + ['class="queryinput"'])
-
-    def test_query_output_section_without_results(self):
-        widget = self._makeWidget()
-        widget.setRenderedValue(self.defaultFieldValue)
-        checks = [
-            "query-results-go-here",
-            ]
-        self.verifyResultMissing(widget.queryview.renderResults([]), checks)
-        self.verifyResultMissing(widget(), checks + ['class="queryresults"'])
-
-    def test_query_output_section_with_results(self):
-        widget = self._makeWidget({'field.f-query': 'foo'})
-        widget.setRenderedValue(self.defaultFieldValue)
-        checks = [
-            "query-results-go-here",
-            ]
-        self.verifyResult(widget.queryview.renderResults([]), checks)
-        self.verifyResult(widget(), checks + ['class="queryresults"'])
-
-
-class SingleSelectionQuerySupportTests(QuerySupportTestBase):
-    """Query support tests for single-selection widgets."""
-
-    defaultFieldValue = "splat"
-    fieldClass = Choice
-    queryViewLabel = "single"
-    _widgetFactory = DropdownWidget
-
-    def makeField(self, vocabulary=None, value=_marker, required=False):
-        """Create and return a bound vocabulary field."""
-        if vocabulary is None:
-            vocabulary = self._sampleVocabulary
-        field = Choice(vocabulary=vocabulary, __name__="f",
-                                 required=required)
-        if value is self._marker:
-            value = self.defaultFieldValue
-        content = SampleContent(value)
-        return field.bind(content)
-
-    def registerViews(self):
-        ztapi.provideMultiView(
-            (ISampleVocabularyQuery, IChoice), IBrowserRequest,
-            IVocabularyQueryView, '', SampleQueryViewSingle)
-
-
-class MultiSelectionQuerySupportTests(QuerySupportTestBase):
-    """Query support tests for multi-selection widgets."""
-
-    defaultFieldValue = ["splat"]
-    fieldClass = List
-    queryViewLabel = "multi"
-    _widgetFactory = MultiSelectWidget
-
-    def makeField(self, vocabulary=None, value=[], required=False):
-        """Create and return a bound vocabulary field."""
-        if vocabulary is None:
-            vocabulary = self._sampleVocabulary
-        field = List(__name__="f",
-                     value_type=Choice(vocabulary=vocabulary,
-                                       required=required))
-        if value is self._marker:
-            value = self.defaultFieldValue
-        content = SampleContent(value)
-        return field.bind(content)
-
-    def registerViews(self):
-        ztapi.provideMultiView(
-            (ISampleVocabularyQuery, ICollection), IBrowserRequest,
-            IVocabularyQueryView, '', SampleQueryViewMulti)
-
-
-def test_suite():
-    suite = unittest.makeSuite(SingleSelectionQuerySupportTests)
-    suite.addTest(unittest.makeSuite(MultiSelectionQuerySupportTests))
-    return suite
-
-if __name__ == '__main__':
-    unittest.main(defaultTest="test_suite")

Deleted: Zope3/trunk/src/zope/app/form/browser/vocabularyquery.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/vocabularyquery.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/form/browser/vocabularyquery.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -1,311 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Browser views for vocabulary widgets.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from zope.interface import implements
-from zope.schema.interfaces import IIterableVocabularyQuery
-
-from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.publisher.browser import BrowserView
-
-from zope.app.form.browser.itemswidgets import TranslationHook, message
-from zope.app.form.browser.interfaces import IVocabularyQueryView
-from zope.app.form.browser.widget import renderElement
-
-ADD_DONE = u"adddone"
-ADD_MORE = u"addmore"
-MORE = u"more"
-
-
-class ActionHelper(TranslationHook):
-    """Helper class to allow sub-actions for a particular widget.
-
-    It is used to execute queries on a large set of vocabulary terms. Note
-    that a vocabulary has to support queries for this."""
-    __actions = None
-
-    def addAction(self, action, msgid):
-        """Add an action for the widget."""
-        if self.__actions is None:
-            self.__actions = {}
-        assert action not in self.__actions
-        self.__actions[action] = msgid
-
-    def getAction(self):
-        """Retrieve a the executed action from the form.
-
-        Return ``None``, if none of the registered actions was called.
-        """
-        assert self.__actions is not None, \
-               "getAction() called on %r with no actions defined" %self
-        for action in self.__actions.iterkeys():
-            name = "%s.action-%s" % (self.name, action)
-            if self.request.form.get(name):
-                return action
-        return None
-
-    def renderAction(self, action, disabled=False):
-        """Render a particular action as a HTML submit button."""
-        msgid = self.__actions[action]
-        return ('<input type="submit" name="%s.action-%s" value=%s %s />'
-                % (self.name, action, quoteattr(self.translate(msgid)),
-                   disabled and 'disabled="disabled"' or ""))
-
-
-class ViewSupport(TranslationHook):
-    """Helper class for vocabulary query views.
-
-    This is mixed into the query view base class.
-    """
-
-    def textForValue(self, term):
-        """Extract a string from the term.
-
-        The `term` must be a vocabulary tokenized term. 
-
-        This can be overridden to support more complex term objects. The token
-        is returned here since it's the only thing known to be a string, or
-        str()able."""
-        return term.token
-
-    def mkselectionlist(self, type, info, name):
-        """Create a list of selections."""
-        items = [self.mkselectionitem(type, name, *item) for item in info]
-        return renderElement("table",
-                             contents="\n%s\n" % "\n".join(items))
-
-    def mkselectionitem(self, type, name, term, selected, disabled):
-        """Create a single secetion item."""
-        flag = ''
-        if selected:
-            flag = ' checked="checked"'
-        if disabled:
-            flag += ' disabled="disabled"'
-        if flag:
-            flag = "\n      " + flag
-        return ('<tr><td>'
-                '<input type="%s" value="%s" name="%s"%s />'
-                '</td>\n    <td>%s</td></tr>'
-                % (type, term.token, name, flag, self.textForValue(term)))
-
-
-class VocabularyQueryViewBase(ActionHelper, ViewSupport, BrowserView):
-    """Vocabulary query support base class."""
-    implements(IVocabularyQueryView)
-
-    def __init__(self, query, field, request):
-        super(VocabularyQueryViewBase, self).__init__(query, request)
-        self.vocabulary = query.vocabulary
-        self.field = field
-        self.widget = None
-
-    def setName(self, name):
-        """See `interfaces.IVocabularyQueryView`"""
-        assert not name.endswith(".")
-        self.name = name
-
-    def setWidget(self, widget):
-        assert self.widget is None
-        assert widget is not None
-        self.widget = widget
-
-    def performAction(self, value):
-        """See `interfaces.IVocabularyQueryView`"""
-        return value
-
-    def renderInput(self):
-        """See `interfaces.IVocabularyQueryView`"""
-        return self._renderQueryInput()
-
-    def renderResults(self, value):
-        """See `interfaces.IVocabularyQueryView`"""
-        results = self._getResults()
-        if results is not None:
-            return self._renderQueryResults(results, value)
-        else:
-            return ""
-
-    def _renderQueryResults(self, results, value):
-        raise NotImplementedError(
-            "_renderQueryResults() must be implemented by a subclass")
-
-    def _renderQueryInput(self):
-        raise NotImplementedError(
-            "_renderQueryInput() must be implemented by a subclass")
-
-    def _getResults(self):
-        # This is responsible for running the query against the query
-        # object (self.context), and returning a results object.  If
-        # there isn't a query in the form, returns None.
-        return None
-
-
-class IterableVocabularyQueryViewBase(VocabularyQueryViewBase):
-    """Query view for `IIterableVocabulary` objects without more
-    specific query views.
-
-    This should only be used (directly) for vocabularies for which
-    `getQuery()` returns ``None``.
-    """
-    queryResultBatchSize = 8
-
-    _msg_add_done = message(_("vocabulary-query-button-add-done"),
-                            "Add+Done")
-    _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 __init__(self, *args, **kw):
-        super(IterableVocabularyQueryViewBase, self).__init__(*args, **kw)
-        self.addAction(ADD_DONE, self._msg_add_done)
-        self.addAction(ADD_MORE, self._msg_add_more)
-        self.addAction(MORE,     self._msg_more)
-
-    def setName(self, name):
-        """See `interfaces.IVocabularyQueryView`"""
-        super(IterableVocabularyQueryViewBase, self).setName(name)
-        name = self.name
-        self.query_index_name = name + ".start"
-        self.query_selections_name = name + ".picks"
-        #
-        get = self.request.form.get
-        self.action = self.getAction()
-        self.query_index = None
-        if self.query_index_name in self.request.form:
-            try:
-                index = int(self.request.form[self.query_index_name])
-            except ValueError:
-                pass
-            else:
-                if index >= 0:
-                    self.query_index = index
-        querySelections = get(self.query_selections_name, [])
-        if not isinstance(querySelections, list):
-            querySelections = [querySelections]
-        self.query_selections = []
-        for token in querySelections:
-            try:
-                term = self.vocabulary.getTermByToken(token)
-            except LookupError:
-                # TODO: unsure what to pass to exception constructor
-                # It is probably the wrong exception to use. You should
-                # probably write a custom one.
-                raise WidgetInputError(
-                    "(query view for %s)" % self.context,
-                    "(query view for %s)" % self.context,
-                    "token %r not in vocabulary" % token)
-            else:
-                self.query_selections.append(term.value)
-
-    def _renderQueryInput(self):
-        # There's no query support, so we can't actually have input.
-        return ""
-
-    def _getResults(self):
-        if self.query_index is not None:
-            return self.vocabulary
-        else:
-            return None
-
-    def _renderQueryResults(self, results, value):
-        # display query results batch
-        it = iter(results)
-        qi = self.query_index
-        have_more = True
-        try:
-            for xxx in range(qi):
-                it.next()
-        except StopIteration:
-            # we should only get here with a botched request; ADD_MORE
-            # and MORE will normally be disabled if there are no results
-            # (see below)
-            have_more = False
-        items = []
-        querySelections = []
-        try:
-            for i in range(qi, qi + self.queryResultBatchSize):
-                term = it.next()
-                disabled = term.value in value
-                selected = disabled
-                if term.value in self.query_selections:
-                    querySelections.append(term.value)
-                    selected = True
-                items.append((term, selected, disabled))
-            else:
-                # see if there's anything else:
-                it.next()
-        except StopIteration:
-            if not items:
-                return "<div class='results'>%s</div>" % (
-                    self.translate(self._msg_no_results))
-            have_more = False
-        self.query_selections = querySelections
-        return ''.join(
-            ["<div class='results'>\n",
-             "<h4>%s</h4>\n" % (
-                 self.translate(self._msg_results_header)),
-             self.makeSelectionList(items, self.query_selections_name),
-             "\n",
-             self.renderAction(ADD_DONE), "\n",
-             self.renderAction(ADD_MORE, not have_more), "\n",
-             self.renderAction(MORE, not have_more), "\n"
-             "<input type='hidden' name='%s' value='%d' />\n"
-             % (self.query_index_name, qi),
-             "</div>"])
-
-    def performAction(self, value):
-        """See `interfaces.IVocabularyQueryView`"""
-        if self.action == ADD_DONE:
-            value = self.addSelections(value)
-            self.query_index = None
-            self.query_selections = []
-        elif self.action == ADD_MORE:
-            value = self.addSelections(value)
-            self.query_index += self.queryResultBatchSize
-        elif self.action == MORE:
-            self.query_index += self.queryResultBatchSize
-        elif self.action:
-            raise ValueError("unknown action in request: %r" % self.action)
-        return value
-
-    def addSelections(self, value):
-        for item in self.query_selections:
-            if item not in value and item in self.vocabulary:
-                value.append(item)
-        return value
-
-
-class IterableVocabularyQueryView(IterableVocabularyQueryViewBase):
-
-    def makeSelectionList(self, items, name):
-        return self.mkselectionlist("radio", items, name)
-
-    def _renderQueryResults(self, results, value):
-        return super(IterableVocabularyQueryView, self)._renderQueryResults(
-            results, [value])
-
-
-class IterableVocabularyQueryMultiView(IterableVocabularyQueryViewBase):
-
-    def makeSelectionList(self, items, name):
-        return self.mkselectionlist("checkbox", items, name)

Modified: Zope3/trunk/src/zope/app/renderer/tests/test_vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/renderer/tests/test_vocabulary.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/renderer/tests/test_vocabulary.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -66,9 +66,6 @@
     def test_len(self):
         self.assertEqual(len(self.vocab), 2)
 
-    def test_getQuery(self):
-        self.assertEqual(self.vocab.getQuery(), None)
-
     def test_getTerm(self):
         self.assertEqual(self.vocab.getTerm('zope.source.Foo').title, 'Foo')
         self.assertRaises(

Modified: Zope3/trunk/src/zope/app/schema/fields.zcml
===================================================================
--- Zope3/trunk/src/zope/app/schema/fields.zcml	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/schema/fields.zcml	2004-10-01 18:22:45 UTC (rev 27731)
@@ -304,7 +304,6 @@
   </content>
 
   <content class="zope.schema.vocabulary.SimpleVocabulary">
-    <allow interface="zope.schema.interfaces.IVocabulary" />
     <allow interface="zope.schema.interfaces.IVocabularyTokenized" />
   </content>
 

Modified: Zope3/trunk/src/zope/app/utility/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/utility/vocabulary.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/utility/vocabulary.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -21,7 +21,6 @@
 from zope.interface.interfaces import IInterface
 from zope.interface.verify import verifyObject
 from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
-from zope.schema.interfaces import IIterableVocabularyQuery
 from zope.schema.interfaces import ITokenizedTerm
 
 from zope.app import zapi
@@ -31,25 +30,6 @@
 from interfaces import IUtilityRegistration
 
 
-class UtilityQuery(object):
-    """Query object for utilities.
-
-    >>> vocab = UtilityVocabulary(None, IInterface)
-    >>> query = UtilityQuery(vocab)
-    >>> verifyObject(IIterableVocabularyQuery, query)
-    True
-
-    >>> query.vocabulary is vocab
-    True
-    """
-    implements(IIterableVocabularyQuery)
-
-    vocabulary = None
-
-    def __init__(self, vocabulary):
-        self.vocabulary = vocabulary
-
-
 class UtilityTerm(object):
     """A term representing a utility.
 
@@ -143,11 +123,8 @@
     3
 
     Next we are looking at some of the more vocabulary-characteristic API
-    methods. First, there is always a query available for the vocabulary:
-
-    >>> vocab.getQuery().__class__.__name__
-    'UtilityQuery'
-
+    methods.
+    
     One can get a term for a given value using getTerm():
 
     >>> vocab.getTerm(object1)
@@ -211,10 +188,6 @@
         """See zope.schema.interfaces.IBaseVocabulary"""
         return value in [term.value for term in self._terms.values()]
 
-    def getQuery(self):
-        """See zope.schema.interfaces.IBaseVocabulary"""
-        return UtilityQuery(self)
-
     def getTerm(self, value):
         """See zope.schema.interfaces.IBaseVocabulary"""
         try:

Modified: Zope3/trunk/src/zope/app/workflow/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/workflow/configure.zcml	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/app/workflow/configure.zcml	2004-10-01 18:22:45 UTC (rev 27731)
@@ -51,7 +51,6 @@
      />
 
   <content class=".definition.ProcessDefinitionVocabulary">
-      <allow interface="zope.schema.interfaces.IVocabulary"/>
       <allow interface="zope.schema.interfaces.IVocabularyTokenized"/>
   </content>
 

Modified: Zope3/trunk/src/zope/schema/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/schema/interfaces.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/interfaces.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -438,27 +438,6 @@
            via a Field.
         """))
 
-class IVocabularyQuery(Interface):
-    """Query object for a vocabulary.
-
-    This is a marker interface for query objects; specific
-    implementations must derive a more specific interface and
-    implement that.  Widget views should be registered for the
-    specific interface.
-    """
-
-    vocabulary = Attribute("vocabulary",
-                           """The source vocabulary for this query object.
-
-                           This needs to be available for use by the
-                           query view.
-                           """)
-
-class IIterableVocabularyQuery(IVocabularyQuery):
-    """Marker interface for a query for a vocabulary that is iterable
-    but does not support a specialized query interface."""
-
-
 class ITerm(Interface):
     """Object representing a single value in a vocabulary."""
 
@@ -495,12 +474,6 @@
     def __contains__(value):
         """Returns True if the value is available in this vocabulary."""
 
-    def getQuery():
-        """Return an IVocabularyQuery object for this vocabulary.
-
-        Vocabularies which do not support query must return None.
-        """
-
     def getTerm(value):
         """Return the ITerm object for the term 'value'.
 
@@ -525,13 +498,13 @@
     """Vocabulary which is iterable."""
 
 
-class IVocabularyTokenized(Interface):
+class IVocabularyTokenized(IVocabulary):
     """Vocabulary that provides support for tokenized representation.
 
     This interface must be used as a mix-in with IBaseVocabulary.
 
     Terms returned from getTerm() and provided by iteration must
-    conform to ITokenizedTerm.
+    conform to ITitledTokenizedTerm.
     """
 
     def getTermByToken(token):

Modified: Zope3/trunk/src/zope/schema/tests/states.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/states.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/tests/states.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -116,9 +116,6 @@
     def __len__(self):
         return len(_states)
 
-    def getQuery(self):
-        return None
-
     def getTerm(self, value):
         return _states[value]
 

Deleted: Zope3/trunk/src/zope/schema/tests/tabcomplete.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/tabcomplete.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/tests/tabcomplete.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -1,76 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Example vocabulary for tab completion.
-
-$Id$
-"""
-from zope.schema.interfaces import ITerm, IVocabulary, IVocabularyQuery
-from zope.interface import implements
-
-
-class IPrefixQuery(IVocabularyQuery):
-    """Interface for prefix queries."""
-
-    def queryForPrefix(prefix):
-        """Return a vocabulary that contains terms beginning with
-        prefix."""
-
-
-class Term(object):
-    implements(ITerm)
-
-    def __init__(self, value):
-        self.value = value
-
-
-class CompletionVocabulary(object):
-    implements(IVocabulary)
-
-    def __init__(self, values):
-        # In practice, something more dynamic could be used to
-        # get the list possible completions.
-        # We force a _values to be a list so we can use .index().
-        self._values = list(values)
-        self._terms = map(Term, self._values)
-
-    def __contains__(self, value):
-        return value in self._values
-
-    def __iter__(self):
-        return iter(self._terms)
-
-    def __len__(self):
-        return len(self._values)
-
-    def getQuery(self):
-        return PrefixQuery(self)
-
-    def getTerm(self, value):
-        if value in self._values:
-            return self._terms[self._values.index(value)]
-        raise LookupError(value)
-
-
-class PrefixQuery(object):
-    implements(IPrefixQuery)
-
-    def __init__(self, vocabulary):
-        self.vocabulary = vocabulary
-
-    def queryForPrefix(self, prefix):
-        L = [v for v in self.vocabulary._values if v.startswith(prefix)]
-        if L:
-            return CompletionVocabulary(L)
-        else:
-            raise LookupError("no entries matching prefix %r" % prefix)

Deleted: Zope3/trunk/src/zope/schema/tests/test_tabcomplete.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/test_tabcomplete.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/tests/test_tabcomplete.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -1,56 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Tests of the 'tab completion' example vocabulary.
-
-$Id$
-"""
-import unittest
-
-from zope.schema.interfaces import ITerm, IVocabularyQuery
-from zope.schema.tests import tabcomplete
-
-
-class TabCompletionTests(unittest.TestCase):
-
-    def setUp(self):
-        self.vocab = tabcomplete.CompletionVocabulary(['abc', 'def'])
-
-    def test_successful_query(self):
-        query = self.vocab.getQuery()
-        subset = query.queryForPrefix("a")
-        L = [term.value for term in subset]
-        self.assertEqual(L, ["abc"])
-        subset = query.queryForPrefix("def")
-        L = [term.value for term in subset]
-        self.assertEqual(L, ["def"])
-
-    def test_failed_query(self):
-        query = self.vocab.getQuery()
-        self.assertRaises(LookupError, query.queryForPrefix, "g")
-
-    def test_query_interface(self):
-        query = self.vocab.getQuery()
-        self.assert_(IVocabularyQuery.providedBy(query))
-
-    def test_getTerm(self):
-        term = self.vocab.getTerm("abc")
-        self.assert_(ITerm.providedBy(term))
-        self.assertEqual(term.value, "abc")
-
-
-def test_suite():
-    return unittest.makeSuite(TabCompletionTests)
-
-if __name__ == "__main__":
-    unittest.main(defaultTest="test_suite")

Modified: Zope3/trunk/src/zope/schema/tests/test_vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/test_vocabulary.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/tests/test_vocabulary.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -72,9 +72,6 @@
     def __len__(self):
         return 10
 
-    def getQuery(self):
-        return None
-
     def getTerm(self, value):
         if value in self:
             t = SampleTerm()
@@ -134,9 +131,6 @@
             self.assert_(1 in v and 2 in v and 3 in v)
             self.assert_(5 not in v)
 
-    def test_get_query(self):
-        self.assert_(self.list_vocab.getQuery() is None)
-
     def test_iter_and_get_term(self):
         for v in (self.list_vocab, self.items_vocab):
             for term in v:

Modified: Zope3/trunk/src/zope/schema/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/schema/vocabulary.py	2004-10-01 10:43:30 UTC (rev 27730)
+++ Zope3/trunk/src/zope/schema/vocabulary.py	2004-10-01 18:22:45 UTC (rev 27731)
@@ -116,10 +116,6 @@
             # sometimes values are not hashable
             return False
 
-    def getQuery(self):
-        """See zope.schema.interfaces.IBaseVocabulary"""
-        return None
-
     def getTerm(self, value):
         """See zope.schema.interfaces.IBaseVocabulary"""
         try:



More information about the Zope3-Checkins mailing list