source: products/quintagroup.portlet.static/trunk/quintagroup/portlet/static/vocabularies.py @ 3218

Last change on this file since 3218 was 3214, checked in by zidane, 13 years ago

corect import IVocabularyFactory, add updating permission for plone 4.1

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1from zope.schema.interfaces 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.static.utils import getVocabulary
8from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _
9
10
11# fallback in case there is no portlet_dropdown lines property inside
12# staticporlet_properties property sheed in portal_properties tool
13PORTLET_CSS_STYLES = (
14    (u"portletStaticClassOne", u"Class One"),
15)
16
17class PortletCSSVocabulary(object):
18    implements(IVocabularyFactory)
19
20    def __call__(self, context):
21        styles = getVocabulary(context)
22        if styles is None:
23            styles = PORTLET_CSS_STYLES
24        charset = self._charset(context)
25        items = []
26        for value, title in styles:
27            if not isinstance(title, unicode):
28                title = title.decode(charset)
29            if not isinstance(value, unicode):
30                value = value.decode(charset)
31            items.append(SimpleTerm(value, value, _(title)))
32        return SimpleVocabulary(items)
33
34    def _charset(self, context):
35        pp = getToolByName(context, 'portal_properties', None)
36        if pp is not None:
37            site_properties = getattr(pp, 'site_properties', None)
38            if site_properties is not None:
39                return site_properties.getProperty('default_charset', 'utf-8')
40        return 'utf-8'
41
42PortletCSSVocabulary = PortletCSSVocabulary()
Note: See TracBrowser for help on using the repository browser.