1 | from zope.interface import implements |
---|
2 | from zope.component import getUtility |
---|
3 | from zope.i18n import translate |
---|
4 | from zope.schema.interfaces import IVocabularyFactory |
---|
5 | |
---|
6 | from Acquisition import aq_inner |
---|
7 | |
---|
8 | from Products.CMFCore.utils import getToolByName |
---|
9 | from Products.CMFEditions.setuphandlers import DEFAULT_POLICIES |
---|
10 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
11 | from Products.CMFPlone import PloneMessageFactory as pmf |
---|
12 | from Products.CMFPlone import utils |
---|
13 | from Products.CMFPlone.browser.navigation import get_view_url |
---|
14 | from Products.Five.browser import BrowserView |
---|
15 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
16 | |
---|
17 | from plone.app.layout.navigation.root import getNavigationRoot |
---|
18 | from plone.app.kss.plonekssview import PloneKSSView |
---|
19 | from plone.app.workflow.remap import remap_workflow |
---|
20 | from plone.memoize.instance import memoize |
---|
21 | from kss.core import kssaction |
---|
22 | |
---|
23 | from quintagroup.plonetabs.config import * |
---|
24 | from interfaces import IPloneTabsControlPanel |
---|
25 | |
---|
26 | def format_description(text, request=None): |
---|
27 | # We expect the workflow to be a text of "- " divided bullet points. |
---|
28 | text = translate(text.strip(), domain="plone", context=request) |
---|
29 | return [s.strip() for s in text.split("- ") if s] |
---|
30 | |
---|
31 | |
---|
32 | class PloneTabsControlPanel(PloneKSSView): |
---|
33 | |
---|
34 | implements(IPloneTabsControlPanel) |
---|
35 | |
---|
36 | actionslist_template = ViewPageTemplateFile("templates/actionslist.pt") |
---|
37 | autogenerated_template = ViewPageTemplateFile("templates/autogenerated.pt") |
---|
38 | |
---|
39 | def getPageTitle(self, category="portal_tabs"): |
---|
40 | """ See interface """ |
---|
41 | portal_props = getToolByName(self.context, "portal_properties") |
---|
42 | default_title = "Plone '%s' Configuration" % category |
---|
43 | |
---|
44 | if not hasattr(portal_props, PROPERTY_SHEET): |
---|
45 | return default_title |
---|
46 | |
---|
47 | sheet = getattr(portal_props, PROPERTY_SHEET) |
---|
48 | if not hasattr(sheet, FIELD_NAME): |
---|
49 | return default_title |
---|
50 | |
---|
51 | field = sheet.getProperty(FIELD_NAME) |
---|
52 | dict = {} |
---|
53 | for line in field: |
---|
54 | cat, title = line.split("|", 2) |
---|
55 | dict[cat] = title |
---|
56 | |
---|
57 | return dict.get(category, None) or default_title |
---|
58 | |
---|
59 | def hasActions(self, category="portal_tabs"): |
---|
60 | """ See interface """ |
---|
61 | return len(getToolByName(self.context, "portal_actions").listActions(categories=[category,])) > 0 |
---|
62 | |
---|
63 | def getPortalActions(self, category="portal_tabs"): |
---|
64 | """ See interface """ |
---|
65 | return getToolByName(self.context, "portal_actions").listActions(categories=[category,]) |
---|
66 | |
---|
67 | def isGeneratedTabs(self): |
---|
68 | """ See interface """ |
---|
69 | site_properties = getToolByName(self.context, "portal_properties").site_properties |
---|
70 | return not site_properties.getProperty("disable_folder_sections", False) |
---|
71 | |
---|
72 | def isNotFoldersGenerated(self): |
---|
73 | """ See interface """ |
---|
74 | site_properties = getToolByName(self.context, "portal_properties").site_properties |
---|
75 | return not site_properties.getProperty("disable_nonfolderish_sections", False) |
---|
76 | |
---|
77 | def getActionsList(self, category="portal_tabs"): |
---|
78 | """ See interface """ |
---|
79 | return self.actionslist_template(category=category) |
---|
80 | |
---|
81 | def getGeneratedTabs(self): |
---|
82 | """ See interface """ |
---|
83 | return self.autogenerated_template() |
---|
84 | |
---|
85 | def getRootTabs(self): |
---|
86 | """ See interface """ |
---|
87 | context = aq_inner(self.context) |
---|
88 | |
---|
89 | portal_catalog = getToolByName(context, 'portal_catalog') |
---|
90 | portal_properties = getToolByName(context, 'portal_properties') |
---|
91 | navtree_properties = getattr(portal_properties, 'navtree_properties') |
---|
92 | |
---|
93 | # Build result dict |
---|
94 | result = [] |
---|
95 | |
---|
96 | # check whether we only want actions |
---|
97 | if not self.isGeneratedTabs(): |
---|
98 | return result |
---|
99 | |
---|
100 | query = {} |
---|
101 | |
---|
102 | rootPath = getNavigationRoot(context) |
---|
103 | query['path'] = {'query' : rootPath, 'depth' : 1} |
---|
104 | query['portal_type'] = utils.typesToList(context) |
---|
105 | |
---|
106 | sortAttribute = navtree_properties.getProperty('sortAttribute', None) |
---|
107 | if sortAttribute is not None: |
---|
108 | query['sort_on'] = sortAttribute |
---|
109 | |
---|
110 | sortOrder = navtree_properties.getProperty('sortOrder', None) |
---|
111 | if sortOrder is not None: |
---|
112 | query['sort_order'] = sortOrder |
---|
113 | |
---|
114 | if navtree_properties.getProperty('enable_wf_state_filtering', False): |
---|
115 | query['review_state'] = navtree_properties.getProperty('wf_states_to_show', []) |
---|
116 | |
---|
117 | query['is_default_page'] = False |
---|
118 | |
---|
119 | if not self.isNotFoldersGenerated(): |
---|
120 | query['is_folderish'] = True |
---|
121 | |
---|
122 | # Get ids not to list and make a dict to make the search fast |
---|
123 | idsNotToList = navtree_properties.getProperty('idsNotToList', ()) |
---|
124 | excludedIds = {} |
---|
125 | for id in idsNotToList: |
---|
126 | excludedIds[id]=1 |
---|
127 | |
---|
128 | rawresult = portal_catalog.searchResults(**query) |
---|
129 | |
---|
130 | # now add the content to results |
---|
131 | for item in rawresult: |
---|
132 | if not excludedIds.has_key(item.getId): |
---|
133 | id, item_url = get_view_url(item) |
---|
134 | data = {'name' : utils.pretty_title_or_id(context, item), |
---|
135 | 'id' : id, |
---|
136 | 'url' : item_url, |
---|
137 | 'description': item.Description, |
---|
138 | 'exclude_from_nav' : item.exclude_from_nav} |
---|
139 | result.append(data) |
---|
140 | |
---|
141 | return result |
---|
142 | |
---|
143 | def getCategories(self): |
---|
144 | """ See interface """ |
---|
145 | portal_actions = getToolByName(self.context, "portal_actions") |
---|
146 | return portal_actions.objectIds() |
---|
147 | |
---|
148 | def test(self, condition, ifTrue, ifFalse): |
---|
149 | """ See interface """ |
---|
150 | if condition: |
---|
151 | return ifTrue |
---|
152 | else: |
---|
153 | return ifFalse |
---|
154 | |
---|
155 | ########################## |
---|
156 | # kss server actions |
---|
157 | ########################## |
---|
158 | |
---|
159 | def updateGlobalSections(self, ksscore): |
---|
160 | """ Method for updating global-sections on client """ |
---|
161 | ksscore.replaceHTML( |
---|
162 | ksscore.getHtmlIdSelector("portal-globalnav"), |
---|
163 | self.macroContent("global_sections/macros/portal_tabs"), |
---|
164 | withKssSetup="False") |
---|
165 | |
---|
166 | @kssaction |
---|
167 | def toggleGeneratedTabs(self, field, checked="0"): |
---|
168 | """ Toggle autogenaration setting on configlet """ |
---|
169 | |
---|
170 | changeProperties = getToolByName(self.context, "portal_properties").site_properties.manage_changeProperties |
---|
171 | if checked == "1": |
---|
172 | changeProperties(**{field : False}) |
---|
173 | else: |
---|
174 | changeProperties(**{field : True}) |
---|
175 | |
---|
176 | ksscore = self.getCommandSet("core") |
---|
177 | replace_id = "roottabs" |
---|
178 | content = self.getGeneratedTabs() |
---|
179 | |
---|
180 | ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector(replace_id), content, withKssSetup="True") |
---|
181 | |
---|
182 | |
---|
183 | self.updateGlobalSections(ksscore) |
---|
184 | |
---|
185 | |
---|
186 | |
---|