Back to index

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

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for available 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.AvailableContentLanguages'
  >>> util = queryUtility(IVocabularyFactory, name)
  >>> context1 = DummyContext()
  >>> context2 = DummyContext()
  >>> context1.context = context2

  >>> util(context1) is None
  True

  >>> tool = DummyTool('portal_languages')
  >>> def getAvailableLanguages():
  ...     return dict(en=dict(name='English'),
  ...                 de=dict(name='German'))
  >>> tool.getAvailableLanguages = getAvailableLanguages
  >>> 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 12 of file language.py.


Member Function Documentation

Definition at line 48 of file language.py.

00048 
00049     def __call__(self, context):
00050         context = getattr(context, 'context', context)
00051         ltool = getToolByName(context, 'portal_languages', None)
00052         if ltool is None:
00053             return None
00054         languages = ltool.getAvailableLanguages()
00055         items = [(l, languages[l].get('name', l)) for l in languages]
00056         items.sort(key=sort_key)
00057         items = [SimpleTerm(i[0], i[0], i[1]) for i in items]
00058         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: