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

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

PPP fixes

File size: 1.9 KB
RevLine 
[3539]1try:
[3555]2    from zope.schema import interfaces
3    IVocabularyFactory = interfaces.IVocabularyFactory
[3539]4except ImportError:
5    from zope.app.schema.vocabulary import IVocabularyFactory
[1572]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 = (
[3555]15    (u"class1", _(u"Class1")),
16    (u"class2", _(u"Class2")),
[1572]17)
18
19PORTLET_ATTRIBUTES_TO_SHOW = (
[3555]20    (u"Title", _(u"Title")),
21    (u"Description", _(u"Description")),
[1572]22)
23
[3555]24
[1572]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
[3555]52
[1572]53class PortletAttributesVocabulary(object):
[3555]54    implements(IVocabularyFactory)
[1572]55
[3555]56    def __call__(self, context):
57        items = [SimpleTerm(value, value, title) for value,
58                 title in PORTLET_ATTRIBUTES_TO_SHOW]
59        return SimpleVocabulary(items)
[1572]60
61PortletAttributesVocabulary = PortletAttributesVocabulary()
Note: See TracBrowser for help on using the repository browser.