[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/security/browser/authservicesearchview.txt Sprinting with Jim:

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Oct 13 04:07:54 EDT 2004


Log message for revision 28041:
  Sprinting with Jim:
  
  Forgot to check in test file.
  

Changed:
  A   Zope3/trunk/src/zope/app/security/browser/authservicesearchview.txt

-=-
Added: Zope3/trunk/src/zope/app/security/browser/authservicesearchview.txt
===================================================================
--- Zope3/trunk/src/zope/app/security/browser/authservicesearchview.txt	2004-10-13 07:42:18 UTC (rev 28040)
+++ Zope3/trunk/src/zope/app/security/browser/authservicesearchview.txt	2004-10-13 08:07:53 UTC (rev 28041)
@@ -0,0 +1,62 @@
+The Query View for Authentication Services
+==========================================
+
+A regular authentication service will not provide the `ISourceQueriables`
+interface, but it is a queriable itself, since it provides the simple
+`getPrincipals(name)` method:
+
+  >>> class Principal:
+  ...     def __init__(self, id): 
+  ...         self.id = id
+
+  >>> class MyAuthService:
+  ...     data = {'jim': Principal(42), 'don': Principal(0), 
+  ...             'stephan': Principal(1)}
+  ...
+  ...     def getPrincipals(self, name):
+  ...         return [principal
+  ...                 for id, principal in self.data.items()
+  ...                 if name in id]
+
+Now that we have our queriable, we create the view for it:
+
+  >>> from zope.app.security.browser.auth import AuthServiceSearchView
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> view = AuthServiceSearchView(MyAuthService(), request)
+
+This allows us to render a search form.
+
+  >>> print view.render('test') # doctest: +NORMALIZE_WHITESPACE
+  <div class="row">
+  <div class="label">
+  Search String
+  </div>
+  <div class="field">
+  <input type="text" name="test.searchstring" />
+  </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.searchstring'] = 'n'
+
+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 (!):
+
+  >>> ids = list(view.results('test'))
+  >>> ids.sort()
+  >>> ids
+  [0, 1]
\ No newline at end of file



More information about the Zope3-Checkins mailing list