1 """
2 """
3 from zope.schema import vocabulary
4 from zope.app.schema.vocabulary import IVocabularyFactory
5 from zope.interface import implements
6 from zope.component import getUtility
7
8 from Products.CMFCore.utils import getToolByName
9 from Products.CMFCore.interfaces import ITypesTool
10 from Products.CMFCore.interfaces import IPropertiesTool
11 from Products.PloneLanguageTool import availablelanguages
12
13 from platecom.utils.i18n import _
14
16 """
17
18 Test ContentTypes vocab,
19
20 >>> from iccommunity.core.vocabularies import ContentTypesVocabularyFactory
21 >>> ccvocab = ContentTypesVocabularyFactory(portal)
22 >>> ccvocab
23 <zope.schema.vocabulary.SimpleVocabulary object at ...>
24 >>> [term.title for term in ccvocab] # doctest: +ELLIPSIS
25 ... +NORMALIZE_WHITESPACE
26 [...u'Event', u'Favorite', u'File', u'Folder', u'Image',
27 u'Large Folder', u'Link', u'News Item', u'Page'...]
28
29 """
30 implements(IVocabularyFactory)
31
32 - def __call__(self, context):
33 context = getattr(context, 'context', context)
34 portal_types = getToolByName(context, 'portal_types')
35 properties = getToolByName(context, 'portal_properties')
36 terms = []
37
38 types = filter( lambda x: x.global_allow, portal_types.objectValues() )
39 types_not_searched = set( properties.site_properties.types_not_searched )
40
41 for type in portal_types.objectValues():
42 if type.getId() not in types_not_searched:
43 terms.append(vocabulary.SimpleTerm(unicode(type.content_meta_type),
44 title=unicode(type.title_or_id())))
45
46 terms.sort( lambda x,y: cmp( x.title, y.title ) )
47
48 return vocabulary.SimpleVocabulary( terms )
49
50 ContentTypesVocabularyFactory = ContentTypesVocabulary()
51
53 implements(IVocabularyFactory)
54
56 langs = []
57 for code, value in availablelanguages.getLanguages().items():
58 if code == "en" or code == "es":
59 langs.append(vocabulary.SimpleTerm(
60 unicode(code),
61 title=unicode(value["english"])
62 )
63 )
64 return vocabulary.SimpleVocabulary( langs )
65
66 LanguagesVocabularyFactory = LanguagesVocabulary()
67