1 | from plone.memoize import ram |
---|
2 | from Products.CMFCore.utils import getToolByName |
---|
3 | from quills.app.portlets.weblogadmin import * |
---|
4 | #from plone.app.portlets.cache import render_cachekey |
---|
5 | |
---|
6 | def _categroies_key(method, self): |
---|
7 | return self.context.getPhysicalPath() |
---|
8 | |
---|
9 | class CustomRenderer(Renderer): |
---|
10 | |
---|
11 | _template = ViewPageTemplateFile('weblogadmin.pt') |
---|
12 | |
---|
13 | @property |
---|
14 | def weblog_url(self): |
---|
15 | weblog_content = self.getWeblogContentObject() |
---|
16 | return weblog_content.absolute_url() |
---|
17 | |
---|
18 | @property |
---|
19 | @ram.cache(_categroies_key) |
---|
20 | def creation_url(self): |
---|
21 | weblog_content = self.getWeblogContentObject() |
---|
22 | try: |
---|
23 | config = IWeblogEnhancedConfiguration(weblog_content) |
---|
24 | type_name = config.default_type |
---|
25 | except TypeError: # Could not adapt, so fall back to default. |
---|
26 | type_name = 'WeblogEntry' |
---|
27 | return "/createObject?type_name=%s" % type_name |
---|
28 | |
---|
29 | @ram.cache(_categroies_key) |
---|
30 | def categories(self): |
---|
31 | weblog_content = self.getWeblogContentObject() |
---|
32 | catalog = getToolByName(self.context, 'portal_catalog') |
---|
33 | bfolders = catalog( |
---|
34 | path='/'.join(weblog_content.getPhysicalPath()), |
---|
35 | portal_type=['Folder','Large Plone Folder'], |
---|
36 | ) |
---|
37 | wc_path_len = len('/'.join(weblog_content.getPhysicalPath())) |
---|
38 | cats = [b.getPath()[wc_path_len+1:] for b in bfolders if not len(b.getPath())==wc_path_len ] |
---|
39 | return cats |
---|
40 | |
---|