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

Last change on this file was 3555, checked in by vmaksymiv, 7 years ago

PPP fixes

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