Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.app.vocabularies.groups.GroupsSource Class Reference

List of all members.

Public Member Functions

def __init__
def __contains__
def search
def get

Public Attributes

 context
 users

Detailed Description

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

  >>> context = DummyContext()

  >>> tool = DummyTool('acl_users')
  >>> groups = ('group1', 'group2')
  >>> def getGroupById(value, default):
  ...     return value in groups and value or default
  >>> 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 ...>

  >>> len(source.search(''))
  2

  >>> len(source.search(u'\xa4'))
  2

  >>> 'group1' in source, 'noone' in source
  (True, False)

  >>> source.get('group1'), source.get('noone')
  ('group1', None)

Definition at line 11 of file groups.py.


Constructor & Destructor Documentation

Definition at line 47 of file groups.py.

00047 
00048     def __init__(self, context):
00049         self.context = context
00050         self.users = getToolByName(context, "acl_users")

Here is the caller graph for this function:


Member Function Documentation

Return whether the value is available in this source

Definition at line 51 of file groups.py.

00051 
00052     def __contains__(self, value):
00053         """Return whether the value is available in this source
00054         """
00055         if self.get(value) is None:
00056             return False
00057         return True

Here is the call graph for this function:

Definition at line 70 of file groups.py.

00070 
00071     def get(self, value):
00072         return self.users.getGroupById(value, None)
00073 

Definition at line 58 of file groups.py.

00058 
00059     def search(self, query):
00060         # XXX: For some reason, this doesn't seem to know how to match on
00061         # title, only name, and seems to match other random groups if
00062         # it's unicode
00063         
00064         try:
00065             name = query.encode('ascii')
00066         except UnicodeEncodeError:
00067             name = query
00068         
00069         return [u['groupid'] for u in self.users.searchGroups(name=name)]
        

Here is the caller graph for this function:


Member Data Documentation

Definition at line 48 of file groups.py.

Definition at line 49 of file groups.py.


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