Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
plone.app.vocabularies.catalog.QuerySearchableTextSourceView 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 DummyCatalog
  >>> 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()

  >>> rids = ('/1234', '/2345', '/dummy/1234')
  >>> tool = DummyCatalog(rids)
  >>> context.portal_catalog = tool

  >>> tool = DummyTool('portal_url')
  >>> def getPortalPath():
  ...     return '/dummy'
  >>> tool.getPortalPath = getPortalPath
  >>> context.portal_url = tool

  >>> source = SearchableTextSource(context)
  >>> source
  <plone.app.vocabularies.catalog.SearchableTextSource object at ...>

  >>> view = QuerySearchableTextSourceView(source, Request())
  >>> view
  <plone.app.vocabularies.catalog.QuerySearchableTextSourceView object ...>

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

  >>> view.getValue('/1234')
  '/1234'

  >>> view.getTerm(None) is None
  True

  >>> view.getTerm('1234')
  <plone.app.vocabularies.terms.BrowsableTerm object at ...>

  >>> view.getTerm('/1234')
  <plone.app.vocabularies.terms.BrowsableTerm object at ...>

  >>> 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 = QuerySearchableTextSourceView(source, request)
  >>> list(view.results('t'))
  ['', '/1234', '']

  >>> request = Request(form={'t.search' : True, 't.query' : 'value',
  ...                         't.browse.foo' : '/foo'})
  >>> view = QuerySearchableTextSourceView(source, request)
  >>> list(view.results('t'))
  ['foo', '', '/1234', '']

Definition at line 231 of file catalog.py.


Constructor & Destructor Documentation

Definition at line 299 of file catalog.py.

00299 
00300     def __init__(self, context, request):
00301         self.context = context
00302         self.request = request

Here is the caller graph for this function:


Member Function Documentation

Definition at line 303 of file catalog.py.

00303 
00304     def getTerm(self, value):
00305         if not value:
00306             return None
00307         if (not self.context.portal_path.endswith('/')) \
00308                and (not value.startswith('/')):
00309             value = '/' + value
00310         # get rid for path
00311         rid = self.context.catalog.getrid(self.context.portal_path + value)
00312         # first some defaults
00313         token = value
00314         title = value
00315         browse_token = None
00316         parent_token = None
00317         if rid is not None:
00318             # fetch the brain from the catalog
00319             brain = self.context.catalog._catalog[rid]
00320             title = brain.Title
00321             if brain.is_folderish:
00322                 browse_token = value
00323             parent_token = "/".join(value.split("/")[:-1])
00324         return BrowsableTerm(value, token=token, title=title, 
00325                              description=value,
00326                              browse_token=browse_token,
00327                              parent_token=parent_token)

Definition at line 328 of file catalog.py.

00328 
00329     def getValue(self, token):
00330         if token not in self.context:
00331             raise LookupError(token)
00332         return token

Here is the caller graph for this function:

Definition at line 333 of file catalog.py.

00333 
00334     def render(self, name):
00335         return self.template(name=name)

Definition at line 336 of file catalog.py.

00336 
00337     def results(self, name):
00338         query = ''
00339 
00340         # check whether the normal search button was pressed
00341         if name+".search" in self.request.form:
00342             query_fieldname = name+".query"
00343             if query_fieldname in self.request.form:
00344                 query = self.request.form[query_fieldname]
00345 
00346         # check whether a browse button was pressed
00347         browse_prefix = name+".browse."
00348         browse = tuple(x for x in self.request.form
00349                        if x.startswith(browse_prefix))
00350         if len(browse) == 1:
00351             path = browse[0][len(browse_prefix):]
00352             query = "path:" + path
00353             results = self.context.search(query)
00354             if name+".omitbrowsedfolder" in self.request.form:
00355                 results = itertools.ifilter(lambda x: x != path, results)
00356         else:
00357             results = self.context.search(query)
00358 
        return results

Here is the caller graph for this function:


Member Data Documentation

Definition at line 300 of file catalog.py.

Definition at line 301 of file catalog.py.

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

Definition at line 297 of file catalog.py.


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