source: products/quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/vocabularies.py @ 3539

Last change on this file since 3539 was 3539, checked in by vmaksymiv, 12 years ago

fixed imports(plone4.1 compatibility)

File size: 1.9 KB
Line 
1try:
2    from zope.schema.interfaces import IVocabularyFactory
3except ImportError:
4    from zope.app.schema.vocabulary import IVocabularyFactory
5from zope.interface import implements
6from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
7
8from Products.CMFCore.utils import getToolByName
9
10from quintagroup.portlet.collection import MessageFactory as _
11from quintagroup.portlet.collection.utils import getStylesVocabulary
12
13PORTLET_CSS_STYLES = (
14     (u"class1", _(u"Class1")),
15     (u"class2", _(u"Class2")),
16)
17
18PORTLET_ATTRIBUTES_TO_SHOW = (
19     (u"Title", _(u"Title")),
20     (u"Description", _(u"Description")),
21)
22
23class PortletCSSVocabulary(object):
24    implements(IVocabularyFactory)
25
26
27    def __call__(self, context):
28        styles = getStylesVocabulary(context)
29        if styles is None:
30            styles = PORTLET_CSS_STYLES
31        charset = self._charset(context)
32        items = []
33        for value, title in styles:
34            if not isinstance(title, unicode):
35                title = title.decode(charset)
36            if not isinstance(value, unicode):
37                value = value.decode(charset)
38            items.append(SimpleTerm(value, value, _(title)))
39        return SimpleVocabulary(items)
40
41    def _charset(self, context):
42        pp = getToolByName(context, 'portal_properties', None)
43        if pp is not None:
44            site_properties = getattr(pp, 'site_properties', None)
45            if site_properties is not None:
46                return site_properties.getProperty('default_charset', 'utf-8')
47            return 'utf-8'
48
49PortletCSSVocabulary = PortletCSSVocabulary()
50
51class PortletAttributesVocabulary(object):
52     implements(IVocabularyFactory)
53
54     def __call__(self, context):
55         items = [SimpleTerm(value, value, title) for value, title in PORTLET_ATTRIBUTES_TO_SHOW]
56         return SimpleVocabulary(items)
57
58PortletAttributesVocabulary = PortletAttributesVocabulary()
59
Note: See TracBrowser for help on using the repository browser.