[285] | 1 | from zope.app.schema.vocabulary import IVocabularyFactory |
---|
| 2 | from zope.interface import implements |
---|
| 3 | from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
---|
| 4 | |
---|
[616] | 5 | from Products.CMFCore.utils import getToolByName |
---|
| 6 | |
---|
| 7 | from quintagroup.portlet.static.utils import getVocabulary |
---|
[285] | 8 | from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _ |
---|
| 9 | |
---|
[561] | 10 | |
---|
[616] | 11 | # fallback in case there is no portlet_dropdown lines property inside |
---|
| 12 | # staticporlet_properties property sheed in portal_properties tool |
---|
[285] | 13 | PORTLET_CSS_STYLES = ( |
---|
[616] | 14 | (u"portletStaticClassOne", u"Class One"), |
---|
[285] | 15 | ) |
---|
| 16 | |
---|
| 17 | class PortletCSSVocabulary(object): |
---|
| 18 | implements(IVocabularyFactory) |
---|
| 19 | |
---|
| 20 | def __call__(self, context): |
---|
[616] | 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))) |
---|
[285] | 32 | return SimpleVocabulary(items) |
---|
| 33 | |
---|
[616] | 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 | |
---|
[285] | 42 | PortletCSSVocabulary = PortletCSSVocabulary() |
---|