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