root/qPloneDropDownMenu/trunk/utils.py

Revision 1411 (checked in by piv, 2 months ago)

now this product is compatible with plone 3

  • Property svn:eol-style set to native
Line 
1 """ Utility functions """
2
3 from zope.component import getMultiAdapter
4
5 from OFS.DTMLMethod import addDTMLMethod
6
7 from Products.CMFCore.utils import getToolByName
8 from Products.CMFPlone.migrations.migration_util import safeEditProperty
9 from Products.CMFCore.Expression import Expression, createExprContext
10
11 from config import PROPERTY_FIELD, PROPERTY_SHEET
12
13 def addCSS(container, sheetId, title, csshovering):
14     """ Add DTML Method object to portal root """
15     addDTMLMethod(container, sheetId, title, csshovering)
16
17 def updateMenu(site):
18     pu = getToolByName(site, 'plone_utils')
19     pa = getToolByName(site, 'portal_actions')
20     portal_props = getToolByName(site, 'portal_properties')
21
22     # collect all portal tabs
23     context_state = getMultiAdapter((site, site.REQUEST), name=u'plone_context_state')
24     actions = context_state.actions()
25     portal_tabs_view = getMultiAdapter((site, site.REQUEST), name='portal_tabs_view')
26     portal_tabs = portal_tabs_view.topLevelTabs(actions=actions)
27
28     # dump to html
29     value = ''
30     for tab in portal_tabs:
31         value += '<li id="portaltab-%s" class="plain">\n' % tab['id']
32         value += '  <a href="%s" accesskey="t" title="%s">%s</a>\n' % (tab['url'], tab['description'], tab['name'])
33         value += '</li>\n'
34
35     if not hasattr(portal_props.aq_base, PROPERTY_SHEET):
36         portal_props.addPropertySheet(PROPERTY_SHEET, 'DropDown Menu Properties')
37     ap = getattr(portal_props.aq_base, PROPERTY_SHEET)
38     safeEditProperty(ap, PROPERTY_FIELD, value, 'text')
Note: See TracBrowser for help on using the browser.