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

Last change on this file since 3218 was 2776, checked in by kroman0, 14 years ago

Fixed support with plone.portlet.static 2.0

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1from zope.interface import implements
2
3from plone.portlets.interfaces import IPortletDataProvider
4from plone.app.portlets.portlets import base
5from plone.portlet.static import static
6from plone.app.form.widgets.wysiwygwidget import WYSIWYGWidget
7
8from zope import schema
9from zope.formlib import form
10from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
11
12from quintagroup.portlet.static.utils import getVocabulary
13from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _
14
15
16class IStaticStylishPortlet(static.IStaticPortlet):
17    """A portlet
18
19    It inherits from IPortletDataProvider because for this portlet, the
20    data that is being rendered and the portlet assignment itself are the
21    same.
22    """
23
24    styling = schema.Choice(title=_(u"Portlet style"),
25                            description=_(u"Choose a css style for the porlet. "
26                                          "You can manage these entries from the plone control panel."),
27                            required=False,
28                            default='',
29                            vocabulary='quintagroup.portlet.static.vocabularies.PortletCSSVocabulary',)
30
31
32class Assignment(static.Assignment):
33    """Portlet assignment.
34
35    This is what is actually managed through the portlets UI and associated
36    with columns.
37    """
38
39    implements(IStaticStylishPortlet)
40
41    styling = ''
42   
43    def __init__(self, header=u"", text=u"", omit_border=False, footer=u"",
44                 more_url='', hide=False, styling=''):
45        super(Assignment, self).__init__(header=header, text=text, omit_border=omit_border, footer=footer,
46                                         more_url=more_url)
47       
48        self.styling = styling
49   
50class Renderer(static.Renderer):
51    """Portlet renderer.
52
53    This is registered in configure.zcml. The referenced page template is
54    rendered, and the implicit variable 'view' will refer to an instance
55    of this class. Other methods can be added and referenced in the template.
56    """
57
58    render = ViewPageTemplateFile('staticstylishportlet.pt')
59
60
61class AddForm(static.AddForm):
62    """Portlet add form.
63
64    This is registered in configure.zcml. The form_fields variable tells
65    zope.formlib which fields to display. The create() method actually
66    constructs the assignment that is being added.
67    """
68    form_fields = form.Fields(IStaticStylishPortlet)
69    form_fields['text'].custom_widget = WYSIWYGWidget
70
71    label = _(u"title_add_staticstylish_portlet", default=u"Add Static Stylish text portlet")
72    description = _(u"description_staticstylish_portlet", default=u"A portlet which can display static HTML text with different styles.")
73
74    def create(self, data):
75        return Assignment(**data)
76
77
78class EditForm(static.EditForm):
79    """Portlet edit form.
80
81    This is registered with configure.zcml. The form_fields variable tells
82    zope.formlib which fields to display.
83    """
84    form_fields = form.Fields(IStaticStylishPortlet)
85    form_fields['text'].custom_widget = WYSIWYGWidget
86
87    label = _(u"title_edit_staticstylish_portlet", default=u"Edit Static Stylish text portlet")
88    description = _(u"description_staticstylish_portlet", default=u"A portlet which can display static HTML text with different styles.")
Note: See TracBrowser for help on using the repository browser.