1 | from zope.schema.interfaces import IVocabularyFactory |
---|
2 | from zope.interface import implements |
---|
3 | from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
---|
4 | from zope.i18n import translate |
---|
5 | |
---|
6 | from Products.CMFCore.utils import getToolByName |
---|
7 | |
---|
8 | from quintagroup.portlet.static.utils import getVocabulary |
---|
9 | from 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 |
---|
14 | PORTLET_CSS_STYLES = ( |
---|
15 | (u"portletStaticClassOne", u"Class One"), |
---|
16 | ) |
---|
17 | |
---|
18 | class 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 | |
---|
43 | PortletCSSVocabulary = PortletCSSVocabulary() |
---|
44 | |
---|
45 | |
---|
46 | class 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 | |
---|
60 | GlobalRolesVocabulary = GlobalRolesVocabulary() |
---|