source: products/quintagroup.portlet.static/trunk/quintagroup/portlet/static/browser/configlet.py @ 3218

Last change on this file since 3218 was 616, checked in by fenix, 18 years ago

fixed view template for campaign content type and increment product version

  • Property svn:eol-style set to native
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.static import StaticStylishPortletMessageFactory as _
18from quintagroup.portlet.static.utils import getVocabulary
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 IStaticStylishPortletPanelSchema(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 static stylish 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 StaticStylishPortletControlPanelAdapter(SchemaAdapterBase):
43    adapts(IPloneSiteRoot)
44    implements(IStaticStylishPortletPanelSchema)
45
46    def __init__(self, context):
47        super(StaticStylishPortletControlPanelAdapter, 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 getVocabulary(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, 'staticportlet_properties', None) is None:
67                self.pp.addPropertySheet(
68                    'staticportlet_properties',
69                    'Static Stylish portlet properties'
70                )
71            sheet = getattr(self.pp, 'staticportlet_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 StaticStylishPortletControlPanel(ControlPanelForm):
82
83    form_fields = form.FormFields(IStaticStylishPortletPanelSchema)
84    form_fields['portlet_dropdown'].custom_widget = combination_widget
85
86    label = _("Static Stylish portlet settings")
87    description = _("This form is for managing Static Stylish portlet "
88                     "classes available on portlet add/edit form.")
89    form_name = _("Static Stylish portlet settings")
90
Note: See TracBrowser for help on using the repository browser.