Changeset 3151 in products for quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
- Timestamp:
- Apr 20, 2011 8:15:52 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
r2843 r3151 24 24 import copy 25 25 26 def cache_key(a,b,c): 26 27 def cache_key(a, b, c): 27 28 return c + str(time() // (60 * 60)) 29 28 30 29 31 class GlobalSectionsViewlet(common.GlobalSectionsViewlet): … … 31 33 recurse = ViewPageTemplateFile('templates/sections_recurse.pt') 32 34 33 34 35 def update(self): 35 36 # we may need some previously defined variables … … 42 43 self.tool = getToolByName(context, 'portal_actions') 43 44 self.site_url = getToolByName(context, 'portal_url')() 44 self.context_state = getMultiAdapter((self.context, self.request), 45 self.context_state = getMultiAdapter((self.context, self.request), 45 46 name="plone_context_state") 46 self.context_url = 47 self.context_url = self.context_state.is_default_page() and \ 47 48 '/'.join(self.context.absolute_url().split('/')[:-1]) or \ 48 49 self.context.absolute_url() 49 50 self.cat_sufix 50 51 self.cat_sufix = self.conf.nested_category_sufix or '' 51 52 self.cat_prefix = self.conf.nested_category_prefix or '' 52 53 # fetch actions-based tabs? … … 78 79 res = copy.deepcopy(res) 79 80 self.tabs = listtabs 80 81 81 82 # if there is no custom menu in portal tabs return 82 83 if not listtabs: 83 84 return [] 84 85 85 86 current_item = -1 86 87 delta = 1000 87 88 for info in listtabs: 88 89 if self.context_url.startswith(info['url']) and \ 89 len(self.context_url) - len(info['url']) < delta:90 delta = len(self.context_url) - len(info['url'])91 current_item = listtabs.index(info)92 self.id_chain = [] 93 90 len(self.context_url) - len(info['url']) < delta: 91 delta = len(self.context_url) - len(info['url']) 92 current_item = listtabs.index(info) 93 self.id_chain = [] 94 94 95 if current_item > -1 and current_item < len(listtabs) and \ 95 96 (listtabs[current_item]['url'] != self.site_url or \ 96 listtabs[current_item]['url'] == self.site_url and self.context_url == self.site_url): 97 self.mark_active(listtabs[current_item]['id'], listtabs[current_item]['url']) 97 listtabs[current_item]['url'] == self.site_url and \ 98 self.context_url == self.site_url): 99 100 self.mark_active(listtabs[current_item]['id'], 101 listtabs[current_item]['url']) 98 102 99 103 self._activate(res) 100 104 return res 101 105 102 106 @ram.cache(cache_key) 103 107 def prepare_tabs(self, site_url): 104 def normalize_actions(category, object, level, parent_url =None):108 def normalize_actions(category, object, level, parent_url=None): 105 109 """walk through the tabs dictionary and build list of all tabs""" 106 110 tabs = [] … … 116 120 subcat = category._getOb(subcat_id) 117 121 if IActionCategory.providedBy(subcat): 118 children = normalize_actions(subcat, object, level+1, info['url']) 119 120 parent_id = category['id'].replace(self.cat_prefix,'').replace(self.cat_sufix,'') 121 tab = {'id' : info['id'], 122 children = normalize_actions(subcat, object, 123 level + 1, 124 info['url']) 125 126 parent_id = category['id'].replace(self.cat_prefix, 127 '').replace(self.cat_sufix, '') 128 tab = {'id': info['id'], 122 129 'title': info['title'], 123 130 'url': info['url'], 124 131 'parent': (parent_id, parent_url)} 125 132 tabslist.append(tab) 126 127 tab = {'id' 133 134 tab = {'id': info['id'], 128 135 'Title': info['title'], 129 136 'Description': info['description'], … … 131 138 'show_children': len(children) > 0, 132 139 'children': children, 133 'currentItem': False, 140 'currentItem': False, 134 141 'currentParent': False, 135 142 'item_icon': {'html_tag': icon}, 136 143 'normalized_review_state': 'visible'} 137 144 tabs.append(tab) 138 return tabs 145 return tabs 139 146 tabslist = [] 140 tabs = normalize_actions(self.tool._getOb(self.conf.actions_category), aq_inner(self.context), 0) 147 tabs = normalize_actions(self.tool._getOb(self.conf.actions_category), 148 aq_inner(self.context), 0) 141 149 return tabs, tabslist 142 150 … … 150 158 self._activate(info['children']) 151 159 152 153 160 def mark_active(self, current_id, url): 154 161 for info in self.tabs: … … 156 163 self.mark_active(info['parent'][0], info['parent'][1]) 157 164 self.id_chain.append(info['url']) 158 159 160 165 161 166 def _actionInfos(self, category, object, check_visibility=1, … … 222 227 def is_plone_four(self): 223 228 """Indicates if we are in plone 4. 224 229 225 230 """ 226 pm = getToolByName(aq_inner(self.context), 'portal_migration') 231 pm = getToolByName(aq_inner(self.context), 'portal_migration') 227 232 try: 228 233 version = versionTupleFromString(pm.getSoftwareVersion()) … … 232 237 if version: 233 238 return version[0] == 4 234
Note: See TracChangeset
for help on using the changeset viewer.