Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
plone.app.vocabularies.users.UsersSourceQueryView Class Reference

List of all members.

Public Member Functions

def __init__
def getTerm
def getValue
def render
def results

Public Attributes

 context
 request

Static Public Attributes

tuple template = ViewPageTemplateFile('searchabletextsource.pt')

Detailed Description

  >>> from plone.app.vocabularies.tests.base import DummyContext
  >>> from plone.app.vocabularies.tests.base import DummyTool
  >>> from plone.app.vocabularies.tests.base import Request

  >>> context = DummyContext()

  >>> class User(object):
  ...     def __init__(self, id):
  ...         self.id = id
  ...
  ...     def getProperty(self, value, default):
  ...         return self.id
  ...
  ...     getId = getProperty

  >>> tool = DummyTool('acl_users')
  >>> users = ('user1', 'user2')
  >>> def getUserById(value, default):
  ...     return value in users and User(value) or None
  >>> tool.getUserById = getUserById
  >>> def searchUsers(fullname=None):
  ...     return [dict(userid=u) for u in users]
  >>> tool.searchUsers = searchUsers
  >>> context.acl_users = tool

  >>> source = UsersSource(context)
  >>> source
  <plone.app.vocabularies.users.UsersSource object at ...>

  >>> view = UsersSourceQueryView(source, Request())
  >>> view
  <plone.app.vocabularies.users.UsersSourceQueryView object at ...>

  >>> view.getTerm('user1')
  <zope.schema.vocabulary.SimpleTerm object at ...>

  >>> view.getValue('user1')
  'user1'

  >>> view.getValue('noone')
  Traceback (most recent call last):
  ...
  LookupError: noone

  >>> template = view.render(name='t')

  >>> u'<input type="text" name="t.query" value="" />' in template
  True

  >>> u'<input type="submit" name="t.search" value="Search" />' in template
  True

  >>> request = Request(form={'t.search' : True, 't.query' : 'value'})
  >>> view = UsersSourceQueryView(source, request)
  >>> view.results('t')
  ['user1', 'user2']

Definition at line 62 of file users.py.


Constructor & Destructor Documentation

def plone.app.vocabularies.users.UsersSourceQueryView.__init__ (   self,
  context,
  request 
)

Definition at line 127 of file users.py.

00127 
00128     def __init__(self, context, request):
00129         self.context = context
00130         self.request = request

Here is the caller graph for this function:


Member Function Documentation

Definition at line 131 of file users.py.

00131 
00132     def getTerm(self, value):
00133         user = self.context.get(value)
00134         token = value
00135         title = value
00136         if user is not None:
00137             title = user.getProperty('fullname', None) or user.getId()
00138         return SimpleTerm(value, token=token, title=title)

Definition at line 139 of file users.py.

00139 
00140     def getValue(self, token):
00141         if token not in self.context:
00142             raise LookupError(token)
00143         return token

Here is the caller graph for this function:

Definition at line 144 of file users.py.

00144 
00145     def render(self, name):
00146         return self.template(name=name)

Definition at line 147 of file users.py.

00147 
00148     def results(self, name):
00149         # check whether the normal search button was pressed
00150         if name+".search" in self.request.form:
00151             query_fieldname = name+".query"
00152             if query_fieldname in self.request.form:
00153                 query = self.request.form[query_fieldname]
00154                 if query != '':
00155                     return self.context.search(query)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 128 of file users.py.

Definition at line 129 of file users.py.

tuple plone.app.vocabularies.users.UsersSourceQueryView.template = ViewPageTemplateFile('searchabletextsource.pt') [static]

Definition at line 125 of file users.py.


The documentation for this class was generated from the following file: