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

Last change on this file since 2755 was 2755, checked in by fenix, 10 years ago
  • added tests;
  • fixed style bug (None class was added when no portlet style is selected);
  • removed trailing characters;
  • removed unnecessary pice of code;
  • some javascript optimizations;
File size: 1.8 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    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
46PortletCSSVocabulary = PortletCSSVocabulary()
47
48class 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
55PortletAttributesVocabulary = PortletAttributesVocabulary()
56
Note: See TracBrowser for help on using the repository browser.