1 | # Zope imports |
---|
2 | from zope.formlib import form |
---|
3 | from zope.interface import implements |
---|
4 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
5 | |
---|
6 | # CMF imports |
---|
7 | from Products.CMFCore.utils import getToolByName |
---|
8 | |
---|
9 | # Plone imports |
---|
10 | from plone.app.portlets.portlets import base |
---|
11 | from plone.app.portlets.browser.formhelper import NullAddForm |
---|
12 | from plone.memoize.instance import memoize |
---|
13 | from plone.portlets.interfaces import IPortletDataProvider |
---|
14 | |
---|
15 | # Quills imports |
---|
16 | from quills.app import QuillsAppMessageFactory as _ |
---|
17 | |
---|
18 | # Local imports |
---|
19 | from quills.app.portlets.base import BasePortletRenderer |
---|
20 | |
---|
21 | |
---|
22 | PORTLET_TITLE = _(u"Weblog Categories") |
---|
23 | PORTLET_DESC = _(u"This portlet provides list of weblog categories.") |
---|
24 | |
---|
25 | |
---|
26 | class IWeblogCategoriesPortlet(IPortletDataProvider): |
---|
27 | """A weblog administration portlet. |
---|
28 | """ |
---|
29 | |
---|
30 | |
---|
31 | class Assignment(base.Assignment): |
---|
32 | implements(IWeblogCategoriesPortlet) |
---|
33 | |
---|
34 | @property |
---|
35 | def title(self): |
---|
36 | return PORTLET_TITLE |
---|
37 | |
---|
38 | |
---|
39 | class Renderer(BasePortletRenderer, base.Renderer): |
---|
40 | |
---|
41 | _template = ViewPageTemplateFile('categories.pt') |
---|
42 | |
---|
43 | @property |
---|
44 | def available(self): |
---|
45 | return self.getCategories() and True or False |
---|
46 | |
---|
47 | @property |
---|
48 | def title(self): |
---|
49 | return PORTLET_TITLE |
---|
50 | |
---|
51 | @memoize |
---|
52 | def getCategories(self): |
---|
53 | cats = [] |
---|
54 | weblog = self.getWeblogContentObject() |
---|
55 | if weblog: |
---|
56 | catalog = getToolByName(self.context, 'portal_catalog') |
---|
57 | bcats = catalog( |
---|
58 | path='/'.join(weblog.getPhysicalPath()), |
---|
59 | portal_type=['Folder','Large Plone Folder'], |
---|
60 | object_provides='quintagroup.quills.extras.browser.interfaces.IWeblogCategory' |
---|
61 | ) |
---|
62 | wbpath = '/'.join(weblog.getPhysicalPath()) |
---|
63 | bcats = filter(lambda b:not b.getPath() == wbpath, bcats) |
---|
64 | cats = [{'title':b.Title or b.getId, 'url':b.getURL} for b in bcats] |
---|
65 | return cats |
---|
66 | |
---|
67 | |
---|
68 | class AddForm(NullAddForm): |
---|
69 | form_fields = form.Fields(IWeblogCategoriesPortlet) |
---|
70 | label = _(u'add-portlet', default=u"Add ${portlet-name} Portlet", |
---|
71 | mapping={u'portlet-name': PORTLET_TITLE}) |
---|
72 | description = PORTLET_DESC |
---|
73 | |
---|
74 | def create(self): |
---|
75 | return Assignment() |
---|
76 | |
---|
77 | |
---|
78 | class EditForm(base.EditForm): |
---|
79 | form_fields = form.Fields(IWeblogCategoriesPortlet) |
---|
80 | label = _(u'edit-portlet', default=u"Edit ${portlet-name} Portlet", mapping={u'portlet-name': PORTLET_TITLE}) |
---|
81 | description = PORTLET_DESC |
---|