[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/groupscontainer/ Added support for `IQuerySchemaSearch`

Amos Brocco amos.brocco at mriyasoftware.com
Wed Oct 13 10:44:56 EDT 2004


Log message for revision 28085:
  Added support for `IQuerySchemaSearch`
  
  

Changed:
  U   Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py
  U   Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
  U   Zope3/trunk/src/zope/app/groupscontainer/interfaces.py
  U   Zope3/trunk/src/zope/app/groupscontainer/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py	2004-10-13 14:37:34 UTC (rev 28084)
+++ Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py	2004-10-13 14:44:54 UTC (rev 28085)
@@ -17,16 +17,19 @@
 
 """
 
-from zope.app.groupscontainer.interfaces import IGroupsFolder
+from zope.app.groupscontainer.interfaces import IGroupsFolder, IGroupSearchCriteria
+from zope.app.pas.interfaces import IQuerySchemaSearch
 from zope.app.container.btree import BTreeContainer
 from zope.interface import implements
 from BTrees.OOBTree import OOBTree
+import zope.schema
 
 
 
 class GroupsFolder(BTreeContainer):
 
-    implements(IGroupsFolder)
+    implements(IGroupsFolder, IQuerySchemaSearch)
+    schema = (IGroupSearchCriteria)
     
     def __init__(self):
         super(BTreeContainer,self).__init__()
@@ -66,3 +69,20 @@
             return self.__getitem__(groupid).principals
         else:
             return []
+
+    def search(self, query, start=None, batch_size=None):
+        """ Search for groups"""
+        search = query.get('search')
+        tmpResults = []
+        if search is not None:
+            i = 0
+            n = 0
+            for value in self.keys():
+                if search in value:
+                    if not ((start is not None and i < start)
+                            or
+                            (batch_size is not None and n > batch_size)):
+                        tmpResults.append(value)
+        return tmpResults
+        
+            

Modified: Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-13 14:37:34 UTC (rev 28084)
+++ Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-13 14:44:54 UTC (rev 28085)
@@ -73,3 +73,52 @@
       ['robots']
       >>> notordinarypeople.getGroupsForPrincipal('2')
       []
+      
+      
+    Now we test the search capabilities, as in IQuerySchemaSearch example:
+    
+    We're trying to search groups in the notordinarypeople class, so first we get a view:
+      
+      >>> import zope.schema
+      >>> from zope.app.pas.browser.schemasearch import QuerySchemaSearchView 
+      >>> from zope.publisher.browser import TestRequest
+      >>> request = TestRequest()
+      >>> view = QuerySchemaSearchView(notordinarypeople, request)
+    
+    This allows us to render a search form.
+    
+      >>> print view.render('test') 
+      <div class="row">
+      <div class="label">
+      <label for="test.field.search" title="">
+      Group Search String
+      </label>
+      </div>
+      <div class="field">
+      <input class="textType" id="test.field.search" name="test.field.search" size="20" type="text" value=""  />
+      </div>
+      </div>
+      <br /><input type="submit" name="test.search" value="Search" />
+
+    If we ask for results:
+    
+      >>> view.results('test')
+    
+    We don't get any, since we did not provide any. But if we give input:
+    
+      >>> request.form['test.field.search'] = 'bo'
+    
+    we still don't get any:
+    
+      >>> view.results('test')
+    
+    because we did not press the button. So let's press the button:
+    
+      >>> request.form['test.search'] = 'Search'
+    
+    so that we now get results (!):
+    
+      >>> view.results('test')
+      [u'robots']
+      >>> request.form['test.field.search'] = 'eek'
+    

Modified: Zope3/trunk/src/zope/app/groupscontainer/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/interfaces.py	2004-10-13 14:37:34 UTC (rev 28084)
+++ Zope3/trunk/src/zope/app/groupscontainer/interfaces.py	2004-10-13 14:44:54 UTC (rev 28085)
@@ -19,7 +19,8 @@
 from zope.app.container.constraints import ContainerTypesConstraint
 from zope.app.container.constraints import ItemTypePrecondition
 from zope.security.interfaces import IGroup
-from zope.schema import Field
+from zope.schema import Field, TextLine
+from zope.interface import Interface
 
 class IGroupsFolder(IContainer):
        
@@ -37,4 +38,8 @@
 class IGroupContained(IContained):
     __parent__ = Field(
              constraint = ContainerTypesConstraint(IGroupsFolder))
+             
 
+class IGroupSearchCriteria(Interface):
+    search = TextLine(title=u"Group Search String")
+

Modified: Zope3/trunk/src/zope/app/groupscontainer/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/tests.py	2004-10-13 14:37:34 UTC (rev 28084)
+++ Zope3/trunk/src/zope/app/groupscontainer/tests.py	2004-10-13 14:44:54 UTC (rev 28085)
@@ -16,7 +16,38 @@
 $Id: tests.py 27237 2004-10-12 10:49:00 mriya3 $
 """
 
+__docformat__ = "reStructuredText"
+import unittest
+from zope.testing import doctest
+from zope.schema.interfaces import ITextLine
+from zope.app.tests import placelesssetup
+from zope.app.tests import ztapi
+from zope.app.form.browser import TextWidget
+from zope.app.form.interfaces import IInputWidget
 
+def setUp(test):
+    placelesssetup.setUp()
+    ztapi.browserView(ITextLine, '', TextWidget, providing=IInputWidget)
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('groupsfolder.txt',
+                             setUp=setUp, tearDown=placelesssetup.tearDown),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+
+
+
+
+
+
+
+
+
+"""
+
 import unittest
 from zope.testing.doctest import DocFileSuite
 
@@ -26,3 +57,4 @@
     return suite
         
     
+"""



More information about the Zope3-Checkins mailing list