[642] | 1 | from zope import schema |
---|
| 2 | from zope.formlib import form |
---|
| 3 | from zope.interface import implements |
---|
| 4 | from zope.component import getMultiAdapter |
---|
| 5 | |
---|
| 6 | from plone.memoize.instance import memoize |
---|
| 7 | from plone.app.portlets.portlets import base |
---|
| 8 | from plone.memoize.compress import xhtml_compress |
---|
| 9 | from plone.portlets.interfaces import IPortletDataProvider |
---|
| 10 | |
---|
| 11 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
| 12 | |
---|
| 13 | # Quills imports |
---|
| 14 | from quills.core.interfaces import IWeblog |
---|
| 15 | from quills.core.interfaces import IWeblogLocator |
---|
| 16 | from quills.app.browser.baseview import BaseView |
---|
| 17 | from quills.app.portlets.base import BasePortletRenderer |
---|
| 18 | |
---|
| 19 | from quintagroup.quills.extras import quintagroupQuillsMessageFactory as _ |
---|
| 20 | |
---|
| 21 | PORTLET_TITLE = _(u"Recent Posts") |
---|
| 22 | PORTLET_DESC = _(u"This portlet lists recent posts for specified weblog.") |
---|
| 23 | |
---|
| 24 | class IRecentWeblogEntriesPortlet(IPortletDataProvider): |
---|
| 25 | |
---|
| 26 | blog = schema.TextLine( |
---|
| 27 | title=_(u"Path to Blog"), |
---|
| 28 | description=_(u"Physical path to blog, from the plone object, 'blog' for ex."), |
---|
| 29 | required=True) |
---|
| 30 | |
---|
| 31 | max_entries = schema.Int( |
---|
| 32 | title=_(u'Maximum entries'), |
---|
| 33 | description=_(u"What's the maximum number of entries to list?"), |
---|
| 34 | required=True, |
---|
| 35 | default=5) |
---|
| 36 | |
---|
| 37 | class Assignment(base.Assignment): |
---|
| 38 | |
---|
| 39 | implements(IRecentWeblogEntriesPortlet) |
---|
| 40 | |
---|
| 41 | def __init__(self, blog='blog', max_entries=5): |
---|
| 42 | self.blog = blog |
---|
| 43 | self.max_entries = max_entries |
---|
| 44 | |
---|
| 45 | @property |
---|
| 46 | def title(self): |
---|
| 47 | return PORTLET_TITLE |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | class Renderer(BasePortletRenderer, base.Renderer, BaseView): |
---|
| 51 | |
---|
| 52 | _template = ViewPageTemplateFile('recententries.pt') |
---|
| 53 | |
---|
| 54 | @property |
---|
| 55 | def title(self): |
---|
| 56 | return PORTLET_TITLE |
---|
| 57 | |
---|
| 58 | @memoize |
---|
| 59 | def getWeblog(self): |
---|
| 60 | pstate = getMultiAdapter((self.context, self.request), name=u'plone_portal_state') |
---|
| 61 | portal = pstate.portal() |
---|
[1256] | 62 | weblog = portal.restrictedTraverse(str(self.data.blog)) |
---|
[642] | 63 | return IWeblog(weblog) |
---|
| 64 | |
---|
| 65 | @property |
---|
| 66 | def getEntries(self): |
---|
| 67 | weblog = self.getWeblog() |
---|
| 68 | return weblog.getEntries(maximum=self.data.max_entries) |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class AddForm(base.AddForm): |
---|
| 72 | form_fields = form.Fields(IRecentWeblogEntriesPortlet) |
---|
| 73 | label = _(u'add-portlet', default=u"Add ${portlet-name} Portlet", mapping={u'portlet-name': PORTLET_TITLE}) |
---|
| 74 | description = PORTLET_DESC |
---|
| 75 | |
---|
| 76 | def create(self, data): |
---|
[1257] | 77 | return Assignment(**data) |
---|
[642] | 78 | |
---|
| 79 | |
---|
| 80 | class EditForm(base.EditForm): |
---|
| 81 | form_fields = form.Fields(IRecentWeblogEntriesPortlet) |
---|
| 82 | label = _(u'edit-portlet', default=u"Edit ${portlet-name} Portlet", mapping={u'portlet-name': PORTLET_TITLE}) |
---|
| 83 | description = PORTLET_DESC |
---|