[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 |
---|
[3282] | 11 | from Products.CMFCore.utils import getToolByName |
---|
| 12 | from Acquisition import aq_inner |
---|
[285] | 13 | |
---|
[616] | 14 | from quintagroup.portlet.static.utils import getVocabulary |
---|
[285] | 15 | from quintagroup.portlet.static import StaticStylishPortletMessageFactory as _ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | class IStaticStylishPortlet(static.IStaticPortlet): |
---|
| 19 | """A portlet |
---|
| 20 | |
---|
| 21 | It inherits from IPortletDataProvider because for this portlet, the |
---|
| 22 | data that is being rendered and the portlet assignment itself are the |
---|
| 23 | same. |
---|
| 24 | """ |
---|
| 25 | |
---|
[3282] | 26 | anonymous_only = schema.Bool( |
---|
| 27 | title=_(u"Anonymous only"), |
---|
| 28 | description=_(u"Check this to hide the portlet for logged-in users."), |
---|
| 29 | required=False, |
---|
| 30 | default=False, |
---|
| 31 | ) |
---|
| 32 | |
---|
[285] | 33 | styling = schema.Choice(title=_(u"Portlet style"), |
---|
[616] | 34 | description=_(u"Choose a css style for the porlet. " |
---|
| 35 | "You can manage these entries from the plone control panel."), |
---|
[285] | 36 | required=False, |
---|
| 37 | default='', |
---|
| 38 | vocabulary='quintagroup.portlet.static.vocabularies.PortletCSSVocabulary',) |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | class Assignment(static.Assignment): |
---|
| 42 | """Portlet assignment. |
---|
| 43 | |
---|
| 44 | This is what is actually managed through the portlets UI and associated |
---|
| 45 | with columns. |
---|
| 46 | """ |
---|
| 47 | |
---|
| 48 | implements(IStaticStylishPortlet) |
---|
| 49 | |
---|
| 50 | styling = '' |
---|
[3282] | 51 | |
---|
| 52 | anonymous_only = False |
---|
| 53 | |
---|
[285] | 54 | def __init__(self, header=u"", text=u"", omit_border=False, footer=u"", |
---|
[3282] | 55 | more_url='', hide=False, styling='', anonymous_only=False): |
---|
[285] | 56 | super(Assignment, self).__init__(header=header, text=text, omit_border=omit_border, footer=footer, |
---|
[2776] | 57 | more_url=more_url) |
---|
[3282] | 58 | |
---|
[285] | 59 | self.styling = styling |
---|
[3282] | 60 | self.anonymous_only = anonymous_only |
---|
| 61 | |
---|
[285] | 62 | class Renderer(static.Renderer): |
---|
| 63 | """Portlet renderer. |
---|
| 64 | |
---|
| 65 | This is registered in configure.zcml. The referenced page template is |
---|
| 66 | rendered, and the implicit variable 'view' will refer to an instance |
---|
| 67 | of this class. Other methods can be added and referenced in the template. |
---|
| 68 | """ |
---|
| 69 | |
---|
| 70 | render = ViewPageTemplateFile('staticstylishportlet.pt') |
---|
| 71 | |
---|
[3282] | 72 | @property |
---|
| 73 | def available(self): |
---|
| 74 | if self.data.anonymous_only: |
---|
| 75 | context = aq_inner(self.context) |
---|
| 76 | mtool = getToolByName(context, 'portal_membership') |
---|
| 77 | return mtool.isAnonymousUser() |
---|
[285] | 78 | |
---|
[3282] | 79 | return True |
---|
| 80 | |
---|
| 81 | |
---|
[285] | 82 | class AddForm(static.AddForm): |
---|
| 83 | """Portlet add form. |
---|
| 84 | |
---|
| 85 | This is registered in configure.zcml. The form_fields variable tells |
---|
| 86 | zope.formlib which fields to display. The create() method actually |
---|
| 87 | constructs the assignment that is being added. |
---|
| 88 | """ |
---|
| 89 | form_fields = form.Fields(IStaticStylishPortlet) |
---|
| 90 | form_fields['text'].custom_widget = WYSIWYGWidget |
---|
| 91 | |
---|
| 92 | label = _(u"title_add_staticstylish_portlet", default=u"Add Static Stylish text portlet") |
---|
| 93 | description = _(u"description_staticstylish_portlet", default=u"A portlet which can display static HTML text with different styles.") |
---|
| 94 | |
---|
| 95 | def create(self, data): |
---|
| 96 | return Assignment(**data) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | class EditForm(static.EditForm): |
---|
| 100 | """Portlet edit form. |
---|
| 101 | |
---|
| 102 | This is registered with configure.zcml. The form_fields variable tells |
---|
| 103 | zope.formlib which fields to display. |
---|
| 104 | """ |
---|
| 105 | form_fields = form.Fields(IStaticStylishPortlet) |
---|
| 106 | form_fields['text'].custom_widget = WYSIWYGWidget |
---|
| 107 | |
---|
| 108 | label = _(u"title_edit_staticstylish_portlet", default=u"Edit Static Stylish text portlet") |
---|
| 109 | description = _(u"description_staticstylish_portlet", default=u"A portlet which can display static HTML text with different styles.") |
---|