1 | from zope.app.schema.vocabulary import IVocabularyFactory |
---|
2 | from zope.interface import implements |
---|
3 | from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
---|
4 | |
---|
5 | from Products.CMFCore.utils import getToolByName |
---|
6 | |
---|
7 | from quintagroup.portlet.collection import MessageFactory as _ |
---|
8 | from quintagroup.portlet.collection.utils import getStylesVocabulary |
---|
9 | |
---|
10 | PORTLET_CSS_STYLES = ( |
---|
11 | (u"class1", _(u"Class1")), |
---|
12 | (u"class2", _(u"Class2")), |
---|
13 | ) |
---|
14 | |
---|
15 | PORTLET_ATTRIBUTES_TO_SHOW = ( |
---|
16 | (u"Title", _(u"Title")), |
---|
17 | (u"Description", _(u"Description")), |
---|
18 | ) |
---|
19 | |
---|
20 | class 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 | def _charset(self, context): |
---|
39 | pp = getToolByName(context, 'portal_properties', None) |
---|
40 | if pp is not None: |
---|
41 | site_properties = getattr(pp, 'site_properties', None) |
---|
42 | if site_properties is not None: |
---|
43 | return site_properties.getProperty('default_charset', 'utf-8') |
---|
44 | return 'utf-8' |
---|
45 | |
---|
46 | PortletCSSVocabulary = PortletCSSVocabulary() |
---|
47 | |
---|
48 | class PortletAttributesVocabulary(object): |
---|
49 | implements(IVocabularyFactory) |
---|
50 | |
---|
51 | def __call__(self, context): |
---|
52 | items = [SimpleTerm(value, value, title) for value, title in PORTLET_ATTRIBUTES_TO_SHOW] |
---|
53 | return SimpleVocabulary(items) |
---|
54 | |
---|
55 | PortletAttributesVocabulary = PortletAttributesVocabulary() |
---|
56 | |
---|