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

Last change on this file since 3336 was 3336, checked in by kroman0, 12 years ago

Excluded/required roles in Static Stylish portlet

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1from zope.schema.interfaces import IVocabularyFactory
2from zope.interface import implements
3from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
4from zope.i18n import translate
5
6from Products.CMFCore.utils import getToolByName
7
8from quintagroup.portlet.static.utils import getVocabulary
9from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _
10
11
12# fallback in case there is no portlet_dropdown lines property inside
13# staticporlet_properties property sheed in portal_properties tool
14PORTLET_CSS_STYLES = (
15    (u"portletStaticClassOne", u"Class One"),
16)
17
18class PortletCSSVocabulary(object):
19    implements(IVocabularyFactory)
20
21    def __call__(self, context):
22        styles = getVocabulary(context)
23        if styles is None:
24            styles = PORTLET_CSS_STYLES
25        charset = self._charset(context)
26        items = []
27        for value, title in styles:
28            if not isinstance(title, unicode):
29                title = title.decode(charset)
30            if not isinstance(value, unicode):
31                value = value.decode(charset)
32            items.append(SimpleTerm(value, value, _(title)))
33        return SimpleVocabulary(items)
34
35    def _charset(self, context):
36        pp = getToolByName(context, 'portal_properties', None)
37        if pp is not None:
38            site_properties = getattr(pp, 'site_properties', None)
39            if site_properties is not None:
40                return site_properties.getProperty('default_charset', 'utf-8')
41        return 'utf-8'
42
43PortletCSSVocabulary = PortletCSSVocabulary()
44
45
46class GlobalRolesVocabulary(object):
47    implements(IVocabularyFactory)
48
49    def __call__(self, context):
50        roles = context.getGlobalPortalRoles()
51
52        return SimpleVocabulary(
53            [SimpleTerm(
54                role, role,
55                translate(role, domain="plone", context=context.REQUEST) \
56                ) for role in roles]
57            )
58
59
60GlobalRolesVocabulary = GlobalRolesVocabulary()
Note: See TracBrowser for help on using the repository browser.