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

Last change on this file since 1572 was 1572, checked in by fenix, 10 years ago

initial package import

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
25class ValueTitlePair(object):
26    implements(IValueTitlePair)
27    def __init__(self, value='', title=''):
28        self.value = value
29        self.title = title
30
31class IQCollectionPortletPanelSchema(Interface):
32
33    portlet_dropdown = schema.List(
34        title=_(u'Dropdown select'),
35        description=_(u"These entries are used for generating dropdown select "
36                      "for quintagroup collection portlet. Note: pipe (|) "
37                      "symbol is not allowed in the value field."),
38        value_type=schema.Object(IValueTitlePair, title=u"entry"),
39        required=True
40    )
41
42class QCollectionPortletControlPanelAdapter(SchemaAdapterBase):
43    adapts(IPloneSiteRoot)
44    implements(IQCollectionPortletPanelSchema)
45
46    def __init__(self, context):
47        super(QCollectionPortletControlPanelAdapter, self).__init__(context)
48        self.context = context
49        self.pp = getToolByName(context, 'portal_properties', None)
50
51    def get_portlet_dropdown(self):
52        return  [ValueTitlePair(v,t) for (v,t) in getStylesVocabulary(self.context)]
53
54    def set_portlet_dropdown(self, value):
55        dropdown_list = []
56        for vt in value:
57            value = vt.value
58            title = vt.title or value
59            dropdown_list.append('%s|%s' % (value, title))
60        self.setValue(dropdown_list)
61
62    portlet_dropdown = property(get_portlet_dropdown, set_portlet_dropdown)
63
64    def setValue(self, value):
65        if self.pp is not None:
66            if getattr(self.pp, 'qcollectionportlet_properties', None) is None:
67                self.pp.addPropertySheet(
68                    'qcollectionportlet_properties',
69                    'QCollection portlet properties'
70                )
71            sheet = getattr(self.pp, 'qcollectionportlet_properties', None)
72            if not sheet.hasProperty('portlet_dropdown'):
73                sheet.manage_addProperty('portlet_dropdown', value, 'lines')
74            else:
75                sheet.manage_changeProperties(portlet_dropdown=value)
76
77valuetitle_widget = CustomWidgetFactory(ObjectWidget, ValueTitlePair)
78combination_widget = CustomWidgetFactory(ListSequenceWidget,
79                                         subwidget=valuetitle_widget)
80
81class QCollectionPortletControlPanel(ControlPanelForm):
82
83    form_fields = form.FormFields(IQCollectionPortletPanelSchema)
84    form_fields['portlet_dropdown'].custom_widget = combination_widget
85
86    label = _("QCollection portlet settings")
87    description = _("This form is for managing QCollection portlet "
88                     "classes available on portlet add/edit form.")
89    form_name = _("QCollection portlet settings")
Note: See TracBrowser for help on using the repository browser.