source: products/quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/browser/configlet.py @ 3556

Last change on this file since 3556 was 3556, checked in by vmaksymiv, 7 years ago

PPP fixes

File size: 3.4 KB
Line 
1from zope.interface import Interface
2from zope.component import adapts
3from zope.interface import implements
4from zope import schema
5from zope.app.form import CustomWidgetFactory
6from zope.app.form.browser import ObjectWidget
7from zope.app.form.browser import ListSequenceWidget
8from zope.formlib import form
9
10from Products.CMFCore.utils import getToolByName
11from Products.CMFDefault.formlib.schema import SchemaAdapterBase
12
13from Products.CMFPlone.interfaces import IPloneSiteRoot
14
15from plone.app.controlpanel.form import ControlPanelForm
16
17from quintagroup.portlet.collection import MessageFactory as _
18from quintagroup.portlet.collection.utils import getStylesVocabulary
19
20
21class IValueTitlePair(Interface):
22    value = schema.TextLine(title=u"value", required=True)
23    title = schema.TextLine(title=u"title", required=False)
24
25
26class ValueTitlePair(object):
27    implements(IValueTitlePair)
28
29    def __init__(self, value='', title=''):
30        self.value = value
31        self.title = title
32
33
34class IQCollectionPortletPanelSchema(Interface):
35
36    portlet_dropdown = schema.List(
37        title=_(u'Dropdown select'),
38        description=_(u"These entries are used for generating dropdown select "
39                      "for quintagroup collection portlet. Note: pipe (|) "
40                      "symbol is not allowed in the value field."),
41        value_type=schema.Object(IValueTitlePair, title=u"entry"),
42        required=True
43    )
44
45
46class QCollectionPortletControlPanelAdapter(SchemaAdapterBase):
47    adapts(IPloneSiteRoot)
48    implements(IQCollectionPortletPanelSchema)
49
50    def __init__(self, context):
51        super(QCollectionPortletControlPanelAdapter, self).__init__(context)
52        self.context = context
53        self.pp = getToolByName(context, 'portal_properties', None)
54
55    def get_portlet_dropdown(self):
56        return [ValueTitlePair(v, t) for (v, t) in getStylesVocabulary(
57            self.context)]
58
59    def set_portlet_dropdown(self, value):
60        dropdown_list = []
61        for vt in value:
62            value = vt.value
63            title = vt.title or value
64            dropdown_list.append('%s|%s' % (value, title))
65        self.setValue(dropdown_list)
66
67    portlet_dropdown = property(get_portlet_dropdown, set_portlet_dropdown)
68
69    def setValue(self, value):
70        if self.pp is not None:
71            if getattr(self.pp, 'qcollectionportlet_properties', None) is None:
72                self.pp.addPropertySheet(
73                    'qcollectionportlet_properties',
74                    'QCollection portlet properties'
75                )
76            sheet = getattr(self.pp, 'qcollectionportlet_properties', None)
77            if not sheet.hasProperty('portlet_dropdown'):
78                sheet.manage_addProperty('portlet_dropdown', value, 'lines')
79            else:
80                sheet.manage_changeProperties(portlet_dropdown=value)
81
82valuetitle_widget = CustomWidgetFactory(ObjectWidget, ValueTitlePair)
83combination_widget = CustomWidgetFactory(ListSequenceWidget,
84                                         subwidget=valuetitle_widget)
85
86
87class QCollectionPortletControlPanel(ControlPanelForm):
88
89    form_fields = form.FormFields(IQCollectionPortletPanelSchema)
90    form_fields['portlet_dropdown'].custom_widget = combination_widget
91
92    label = _("QCollection portlet settings")
93    description = _("This form is for managing QCollection portlet "
94                    "classes available on portlet add/edit form.")
95    form_name = _("QCollection portlet settings")
Note: See TracBrowser for help on using the repository browser.