Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
plone.app.vocabularies.groups.GroupsSourceQueryView 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 Group(object):
  ...     def __init__(self, id):
  ...         self.id = id
  ...
  ...     def getProperty(self, value, default):
  ...         return self.id
  ...
  ...     getId = getProperty

  >>> tool = DummyTool('acl_users')
  >>> groups = ('group1', 'group2')
  >>> def getGroupById(value, default):
  ...     return value in groups and Group(value) or None
  >>> tool.getGroupById = getGroupById
  >>> def searchGroups(name=None):
  ...     return [dict(groupid=u) for u in groups]
  >>> tool.searchGroups = searchGroups
  >>> context.acl_users = tool

  >>> source = GroupsSource(context)
  >>> source
  <plone.app.vocabularies.groups.GroupsSource object at ...>

  >>> view = GroupsSourceQueryView(source, Request())
  >>> view
  <plone.app.vocabularies.groups.GroupsSourceQueryView object at ...>

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

  >>> view.getValue('group1')
  'group1'

  >>> 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 = GroupsSourceQueryView(source, request)
  >>> view.results('t')
  ['group1', 'group2']

Definition at line 74 of file groups.py.


Constructor & Destructor Documentation

def plone.app.vocabularies.groups.GroupsSourceQueryView.__init__ (   self,
  context,
  request 
)

Definition at line 138 of file groups.py.

00138 
00139     def __init__(self, context, request):
00140         self.context = context
00141         self.request = request

Here is the caller graph for this function:


Member Function Documentation

Definition at line 142 of file groups.py.

00142 
00143     def getTerm(self, value):
00144         group = self.context.get(value)
00145         token = value
00146         title = value
00147         if group is not None:
00148             title = group.getProperty('title', None) or group.getId()
00149         return SimpleTerm(value, token=token, title=title)

Definition at line 150 of file groups.py.

00150 
00151     def getValue(self, token):
00152         if token not in self.context:
00153             raise LookupError(token)
00154         return token

Here is the caller graph for this function:

Definition at line 155 of file groups.py.

00155 
00156     def render(self, name):
00157         return self.template(name=name)

Definition at line 158 of file groups.py.

00158 
00159     def results(self, name):
00160         # check whether the normal search button was pressed
00161         if name+".search" in self.request.form:
00162             query_fieldname = name+".query"
00163             if query_fieldname in self.request.form:
00164                 query = self.request.form[query_fieldname]
00165                 if query != '':
00166                     return self.context.search(query)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 139 of file groups.py.

Definition at line 140 of file groups.py.

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

Definition at line 136 of file groups.py.


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