[285] | 1 | from zope.interface import implements |
---|
| 2 | |
---|
| 3 | from plone.portlets.interfaces import IPortletDataProvider |
---|
| 4 | from plone.app.portlets.portlets import base |
---|
| 5 | from plone.portlet.static import static |
---|
| 6 | from plone.app.form.widgets.wysiwygwidget import WYSIWYGWidget |
---|
| 7 | |
---|
| 8 | from zope import schema |
---|
| 9 | from zope.formlib import form |
---|
| 10 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
| 11 | |
---|
[616] | 12 | from quintagroup.portlet.static.utils import getVocabulary |
---|
[285] | 13 | from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class 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"), |
---|
[616] | 25 | description=_(u"Choose a css style for the porlet. " |
---|
| 26 | "You can manage these entries from the plone control panel."), |
---|
[285] | 27 | required=False, |
---|
| 28 | default='', |
---|
| 29 | vocabulary='quintagroup.portlet.static.vocabularies.PortletCSSVocabulary',) |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | class 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, |
---|
[2776] | 46 | more_url=more_url) |
---|
[285] | 47 | |
---|
| 48 | self.styling = styling |
---|
| 49 | |
---|
| 50 | class 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 | |
---|
| 61 | class 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 | |
---|
| 78 | class 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.") |
---|