[1] | 1 | import string |
---|
| 2 | from cStringIO import StringIO |
---|
| 3 | |
---|
| 4 | from Products.CMFCore.utils import getToolByName |
---|
| 5 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
| 6 | |
---|
| 7 | from Products.CMFPlone.migrations.migration_util import safeEditProperty |
---|
| 8 | from Products.CMFCore.Expression import Expression, createExprContext |
---|
| 9 | |
---|
| 10 | from Products.qPloneDropDownMenu.config import * |
---|
| 11 | |
---|
| 12 | configlets = ({'id':PROJECT_NAME, |
---|
| 13 | 'name':'Drop Down Menu', |
---|
| 14 | 'action':'string:${portal_url}/prefs_dropdownmenu_edit_form', |
---|
| 15 | 'condition':'', |
---|
| 16 | 'category':'Products', |
---|
| 17 | 'visible':1, |
---|
| 18 | 'appId':PROJECT_NAME, |
---|
| 19 | 'permission':VIEW_PERMISSION, |
---|
| 20 | 'imageUrl':'qplonedropdownmenu.gif' },) |
---|
| 21 | |
---|
| 22 | def registerCSS(self, out): |
---|
| 23 | |
---|
| 24 | qi = getToolByName(self, 'portal_quickinstaller', None) |
---|
| 25 | if qi is not None: |
---|
| 26 | try: |
---|
| 27 | if not qi.isProductInstalled('ResourceRegistries'): |
---|
| 28 | qi.installProduct('ResourceRegistries', locked=0) |
---|
| 29 | cssreg = getToolByName(self, 'portal_css', None) |
---|
| 30 | if cssreg is not None: |
---|
| 31 | stylesheet_ids = cssreg.getResourceIds() |
---|
| 32 | |
---|
| 33 | if 'drop_down.css' not in stylesheet_ids: |
---|
| 34 | cssreg.registerStylesheet('drop_down.css', |
---|
| 35 | expression="python:portal.portal_dropdownmenu") |
---|
| 36 | out.write('Register drop_down.css... \n') |
---|
| 37 | else: |
---|
| 38 | out.write('drop_down.css already exists... \n') |
---|
| 39 | except: |
---|
| 40 | pass |
---|
| 41 | |
---|
| 42 | def unregisterCSS(self, out): |
---|
| 43 | |
---|
| 44 | qi = getToolByName(self, 'portal_quickinstaller', None) |
---|
| 45 | if qi is not None: |
---|
| 46 | try: |
---|
| 47 | if not qi.isProductInstalled('ResourceRegistries'): |
---|
| 48 | qi.installProduct('ResourceRegistries', locked=0) |
---|
| 49 | cssreg = getToolByName(self, 'portal_css', None) |
---|
| 50 | if cssreg is not None: |
---|
| 51 | stylesheet_ids = cssreg.getResourceIds() |
---|
| 52 | |
---|
| 53 | if 'drop_down.css' in stylesheet_ids: |
---|
| 54 | cssreg.unregisterResource('drop_down.css') |
---|
| 55 | out.write('Unregister drop_down.css... \n') |
---|
| 56 | except: |
---|
| 57 | pass |
---|
| 58 | |
---|
| 59 | def updateMenu(self): |
---|
| 60 | out = '' |
---|
| 61 | |
---|
| 62 | pu = getToolByName(self, 'plone_utils') |
---|
| 63 | |
---|
| 64 | if hasattr(pu, 'createTopLevelTabs'): |
---|
| 65 | pactions = getToolByName(self, 'portal_actions').listFilteredActionsFor(self) |
---|
| 66 | tl_tabs = pu.createTopLevelTabs(pactions) |
---|
| 67 | |
---|
| 68 | for act in tl_tabs: |
---|
| 69 | out += '<li id="portaltab-%s" class="plain"><a href="%s" accesskey="t">' % \ |
---|
| 70 | (act['id'], act['url']) + act['name'] + '</a></li>\n' |
---|
| 71 | else: |
---|
| 72 | portal = getToolByName(self, 'portal_url').getPortalObject() |
---|
| 73 | |
---|
| 74 | portal_act = getToolByName(self, 'portal_actions') |
---|
| 75 | actions=portal_act._cloneActions() |
---|
| 76 | |
---|
| 77 | for act in actions: |
---|
| 78 | if act.category == 'portal_tabs': |
---|
| 79 | out += '<li id="portaltab-%s" class="plain"><a href="%s" accesskey="t">%s</a></li>\n' % \ |
---|
| 80 | (act.id, \ |
---|
| 81 | Expression(act.getActionExpression())(createExprContext(portal, portal, portal)), \ |
---|
| 82 | act.title) |
---|
| 83 | |
---|
| 84 | portal_props = getToolByName(self, 'portal_properties') |
---|
| 85 | if not hasattr(portal_props, PROPERTY_SHEET): |
---|
| 86 | portal_props.addPropertySheet(PROPERTY_SHEET, 'DropDown Menu Properties') |
---|
| 87 | ap = getattr(portal_props, PROPERTY_SHEET) |
---|
| 88 | safeEditProperty(ap, 'menu', out, 'text') |
---|
| 89 | |
---|
| 90 | def setupSkin(self, out, skinFolder): |
---|
| 91 | |
---|
| 92 | skinstool=getToolByName(self, 'portal_skins') |
---|
| 93 | |
---|
| 94 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
| 95 | |
---|
| 96 | for skin in skinstool.getSkinSelections(): |
---|
| 97 | path = skinstool.getSkinPath(skin) |
---|
| 98 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 99 | |
---|
| 100 | if not skinFolder in path: |
---|
| 101 | try: |
---|
| 102 | path.insert( path.index( 'custom')+1, skinFolder ) |
---|
| 103 | except ValueError: |
---|
| 104 | path.append(skinFolder) |
---|
| 105 | path = string.join( path, ', ' ) |
---|
| 106 | skinstool.addSkinSelection( skin, path ) |
---|
| 107 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 108 | else: |
---|
| 109 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 110 | |
---|
| 111 | def setupTool(self): |
---|
| 112 | |
---|
| 113 | portal_url = getToolByName(self, 'portal_url') |
---|
| 114 | p = portal_url.getPortalObject() |
---|
| 115 | x = p.manage_addProduct[PROJECT_NAME].manage_addTool(type='DropDownMenu Tool') |
---|
| 116 | |
---|
| 117 | def install(self): |
---|
| 118 | out = StringIO() |
---|
| 119 | |
---|
| 120 | registerCSS(self, out) |
---|
| 121 | |
---|
| 122 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
| 123 | if configTool: |
---|
| 124 | for conf in configlets: |
---|
| 125 | configTool.registerConfiglet(**conf) |
---|
| 126 | out.write('Added configlet %s\n' % conf['id']) |
---|
| 127 | |
---|
| 128 | if hasattr(self, UNIQUE_ID): |
---|
| 129 | self.manage_delObjects([UNIQUE_ID]) |
---|
| 130 | out.write('Deleting old %s\n' % (UNIQUE_ID)) |
---|
| 131 | setupTool(self) |
---|
| 132 | out.write('Added %s to the portal root folder\n' % (UNIQUE_ID)) |
---|
| 133 | |
---|
| 134 | portal_props = getToolByName(self, 'portal_properties') |
---|
| 135 | if not hasattr(portal_props, PROPERTY_SHEET): |
---|
| 136 | out.write('updateMenu... \n') |
---|
| 137 | updateMenu(self) |
---|
| 138 | else: |
---|
| 139 | out.write('skipping updateMenu... \n') |
---|
| 140 | |
---|
| 141 | out.write('setupSkin... \n') |
---|
| 142 | setupSkin(self, out, 'qPloneDropDownMenu') |
---|
| 143 | |
---|
| 144 | return out.getvalue() |
---|
| 145 | |
---|
| 146 | def uninstall(self): |
---|
| 147 | out = StringIO() |
---|
| 148 | |
---|
| 149 | unregisterCSS(self, out) |
---|
| 150 | |
---|
| 151 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
| 152 | if configTool: |
---|
| 153 | for conf in configlets: |
---|
| 154 | configTool.unregisterConfiglet(conf['id']) |
---|
| 155 | out.write('Removed configlet %s\n' % conf['id']) |
---|
| 156 | |
---|
| 157 | return out.getvalue() |
---|