[3539] | 1 | try: |
---|
| 2 | from zope.schema.interfaces import IVocabularyFactory |
---|
| 3 | except ImportError: |
---|
| 4 | from zope.app.schema.vocabulary import IVocabularyFactory |
---|
[1572] | 5 | from zope.interface import implements |
---|
| 6 | from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
---|
| 7 | |
---|
| 8 | from Products.CMFCore.utils import getToolByName |
---|
| 9 | |
---|
| 10 | from quintagroup.portlet.collection import MessageFactory as _ |
---|
| 11 | from quintagroup.portlet.collection.utils import getStylesVocabulary |
---|
| 12 | |
---|
| 13 | PORTLET_CSS_STYLES = ( |
---|
| 14 | (u"class1", _(u"Class1")), |
---|
| 15 | (u"class2", _(u"Class2")), |
---|
| 16 | ) |
---|
| 17 | |
---|
| 18 | PORTLET_ATTRIBUTES_TO_SHOW = ( |
---|
| 19 | (u"Title", _(u"Title")), |
---|
| 20 | (u"Description", _(u"Description")), |
---|
| 21 | ) |
---|
| 22 | |
---|
| 23 | class PortletCSSVocabulary(object): |
---|
| 24 | implements(IVocabularyFactory) |
---|
| 25 | |
---|
[2755] | 26 | |
---|
[1572] | 27 | def __call__(self, context): |
---|
| 28 | styles = getStylesVocabulary(context) |
---|
| 29 | if styles is None: |
---|
| 30 | styles = PORTLET_CSS_STYLES |
---|
| 31 | charset = self._charset(context) |
---|
| 32 | items = [] |
---|
| 33 | for value, title in styles: |
---|
| 34 | if not isinstance(title, unicode): |
---|
| 35 | title = title.decode(charset) |
---|
| 36 | if not isinstance(value, unicode): |
---|
| 37 | value = value.decode(charset) |
---|
| 38 | items.append(SimpleTerm(value, value, _(title))) |
---|
| 39 | return SimpleVocabulary(items) |
---|
| 40 | |
---|
| 41 | def _charset(self, context): |
---|
| 42 | pp = getToolByName(context, 'portal_properties', None) |
---|
| 43 | if pp is not None: |
---|
| 44 | site_properties = getattr(pp, 'site_properties', None) |
---|
| 45 | if site_properties is not None: |
---|
| 46 | return site_properties.getProperty('default_charset', 'utf-8') |
---|
| 47 | return 'utf-8' |
---|
| 48 | |
---|
| 49 | PortletCSSVocabulary = PortletCSSVocabulary() |
---|
| 50 | |
---|
| 51 | class PortletAttributesVocabulary(object): |
---|
| 52 | implements(IVocabularyFactory) |
---|
| 53 | |
---|
| 54 | def __call__(self, context): |
---|
| 55 | items = [SimpleTerm(value, value, title) for value, title in PORTLET_ATTRIBUTES_TO_SHOW] |
---|
| 56 | return SimpleVocabulary(items) |
---|
| 57 | |
---|
| 58 | PortletAttributesVocabulary = PortletAttributesVocabulary() |
---|
| 59 | |
---|