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

Last change on this file since 1572 was 1572, checked in by fenix, 10 years ago

initial package import

File size: 1.9 KB
Line 
1from zope.app.schema.vocabulary import IVocabularyFactory
2from zope.interface import implements
3from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
4
5from Products.CMFCore.utils import getToolByName
6
7from quintagroup.portlet.collection import MessageFactory as _
8from quintagroup.portlet.collection.utils import getStylesVocabulary
9
10PORTLET_CSS_STYLES = (
11     (u"class1", _(u"Class1")),
12     (u"class2", _(u"Class2")),
13)
14
15PORTLET_ATTRIBUTES_TO_SHOW = (
16     (u"Title", _(u"Title")),
17     (u"Description", _(u"Description")),
18)
19
20class PortletCSSVocabulary(object):
21    implements(IVocabularyFactory)
22
23   
24    def __call__(self, context):
25        styles = getStylesVocabulary(context)
26        if styles is None:
27            styles = PORTLET_CSS_STYLES
28        charset = self._charset(context)
29        items = []
30        for value, title in styles:
31            if not isinstance(title, unicode):
32                title = title.decode(charset)
33            if not isinstance(value, unicode):
34                value = value.decode(charset)
35            items.append(SimpleTerm(value, value, _(title)))
36        return SimpleVocabulary(items)
37
38        items = [SimpleTerm(value, value, title) for value, title in PORTLET_CSS_STYLES]
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.