[1579] | 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.compress import xhtml_compress |
---|
| 7 | from plone.portlets.interfaces import IPortletDataProvider |
---|
| 8 | |
---|
| 9 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
| 10 | |
---|
| 11 | # Quills imports |
---|
| 12 | from quills.core.interfaces import IBaseContent |
---|
| 13 | from quills.core.interfaces import IWeblogEnhanced |
---|
| 14 | from quills.core.interfaces import IWeblog |
---|
| 15 | from quills.app.utilities import recurseToInterface |
---|
| 16 | from quills.app.utilities import talkbackURL |
---|
| 17 | from quills.app.utilities import getArchiveURLFor |
---|
| 18 | from quills.app.browser.baseview import BaseView |
---|
| 19 | from quills.app import QuillsAppMessageFactory as _ |
---|
| 20 | |
---|
| 21 | # Local imports |
---|
| 22 | from quills.app.portlets import recentcomments as base |
---|
| 23 | from quills.app.portlets.base import BasePortletRenderer |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | PORTLET_TITLE = _(u"Recent Comments") |
---|
| 27 | PORTLET_DESC = _(u"This portlet lists recent weblog comments.") |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | class IRecentCommentsPortlet(base.IRecentWeblogCommentsPortlet): |
---|
| 31 | |
---|
| 32 | blog_path = schema.TextLine( |
---|
| 33 | title=_(u"Path to Blog"), |
---|
| 34 | description=_(u"Physical path to blog, from the plone object, 'blog' for ex."), |
---|
| 35 | required=True) |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | class Assignment(base.Assignment): |
---|
| 39 | |
---|
| 40 | implements(IRecentCommentsPortlet) |
---|
| 41 | |
---|
| 42 | def __init__(self, max_comments=5, blog_path='blog'): |
---|
| 43 | super(Assignment, self).__init__(max_comments = max_comments) |
---|
| 44 | self.blog_path = blog_path |
---|
| 45 | |
---|
| 46 | @property |
---|
| 47 | def title(self): |
---|
| 48 | return PORTLET_TITLE |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | class Renderer(BasePortletRenderer, base.Renderer, BaseView): |
---|
| 52 | |
---|
| 53 | _template = ViewPageTemplateFile('recentcomments.pt') |
---|
| 54 | |
---|
| 55 | @property |
---|
| 56 | def available(self): |
---|
| 57 | return len(self.getComments) > 0 |
---|
| 58 | |
---|
| 59 | @property |
---|
| 60 | def title(self): |
---|
| 61 | return PORTLET_TITLE |
---|
| 62 | |
---|
| 63 | def getWeblog(self): |
---|
| 64 | pstate = getMultiAdapter((self.context, self.request), name=u'plone_portal_state') |
---|
| 65 | portal = pstate.portal() |
---|
| 66 | weblog = portal.restrictedTraverse(str(self.data.blog_path)) |
---|
| 67 | return IWeblog(weblog) |
---|
| 68 | |
---|
| 69 | class AddForm(base.AddForm): |
---|
| 70 | form_fields = form.Fields(IRecentCommentsPortlet) |
---|
| 71 | label = _(u'add-portlet', default=u"Add ${portlet-name} Portlet", mapping={u'portlet-name': PORTLET_TITLE}) |
---|
| 72 | description = PORTLET_DESC |
---|
| 73 | |
---|
| 74 | def create(self, data): |
---|
| 75 | return Assignment(max_comments=5, blog_path='blog') |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | class EditForm(base.EditForm): |
---|
| 79 | form_fields = form.Fields(IRecentCommentsPortlet) |
---|
| 80 | label = _(u'edit-portlet', default=u"Edit ${portlet-name} Portlet", mapping={u'portlet-name': PORTLET_TITLE}) |
---|
| 81 | description = PORTLET_DESC |
---|