Back to index

plone3  3.1.7
Public Member Functions
plone.app.vocabularies.language.SupportedContentLanguageVocabulary Class Reference

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for supported content languages in the portal.

  >>> from zope.component import queryUtility
  >>> from plone.app.vocabularies.tests.base import DummyContext
  >>> from plone.app.vocabularies.tests.base import DummyTool

  >>> name = 'plone.app.vocabularies.SupportedContentLanguages'
  >>> util = queryUtility(IVocabularyFactory, name)
  >>> context1 = DummyContext()
  >>> context2 = DummyContext()
  >>> context1.context = context2

  >>> util(context1) is None
  True

  >>> tool = DummyTool('portal_languages')
  >>> def listSupportedLanguages():
  ...     return [('en', 'English'), ('de', 'German')]
  >>> tool.listSupportedLanguages = listSupportedLanguages
  >>> context2.portal_languages = tool

  >>> languages = util(context1)
  >>> languages
  <zope.schema.vocabulary.SimpleVocabulary object at ...>

  >>> len(languages.by_token)
  2

  >>> de = languages.by_token['de']
  >>> de.title, de.token, de.value
  ('German', 'de', 'de')

Definition at line 62 of file language.py.


Member Function Documentation

Definition at line 97 of file language.py.

00097 
00098     def __call__(self, context):
00099         context = getattr(context, 'context', context)
00100         ltool = getToolByName(context, 'portal_languages', None)
00101         if ltool is None:
00102             return None
00103         items = ltool.listSupportedLanguages()
00104         items.sort(key=sort_key)
00105         items = [SimpleTerm(i[0], i[0], i[1]) for i in items]
00106         return SimpleVocabulary(items)

Here is the call graph for this function:

Here is the caller graph for this function:


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