[1] | 1 | import string |
---|
| 2 | from cStringIO import StringIO |
---|
| 3 | |
---|
| 4 | from Products.Archetypes import listTypes |
---|
| 5 | from Products.Archetypes.Extensions.utils import installTypes |
---|
| 6 | |
---|
| 7 | from Products.CMFCore.utils import getToolByName |
---|
| 8 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
| 9 | |
---|
| 10 | from Products.qSiloGroup.config import * |
---|
| 11 | |
---|
| 12 | def removeSkin(self, layer): |
---|
| 13 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 14 | for skinName in skinstool.getSkinSelections(): |
---|
| 15 | original_path = skinstool.getSkinPath(skinName) |
---|
| 16 | original_path = [l.strip() for l in original_path.split(',')] |
---|
| 17 | new_path= [] |
---|
| 18 | for l in original_path: |
---|
| 19 | if (l == layer) or (l.startswith(layer+'/')): |
---|
| 20 | continue |
---|
| 21 | new_path.append(l) |
---|
| 22 | skinstool.addSkinSelection(skinName, ','.join(new_path)) |
---|
| 23 | |
---|
| 24 | def setupSkin(self, out, skinFolder): |
---|
| 25 | |
---|
| 26 | skinstool=getToolByName(self, 'portal_skins') |
---|
| 27 | |
---|
| 28 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
| 29 | |
---|
| 30 | for skin in skinstool.getSkinSelections(): |
---|
| 31 | path = skinstool.getSkinPath(skin) |
---|
| 32 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 33 | |
---|
| 34 | if not skinFolder in path: |
---|
| 35 | try: |
---|
| 36 | path.insert( path.index( 'custom')+1, skinFolder ) |
---|
| 37 | except ValueError: |
---|
| 38 | path.append(skinFolder) |
---|
| 39 | path = string.join( path, ', ' ) |
---|
| 40 | skinstool.addSkinSelection( skin, path ) |
---|
| 41 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 42 | else: |
---|
| 43 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 44 | |
---|
| 45 | def setupActions(self, out): |
---|
| 46 | out.write("Inspecting portal_types\n") |
---|
| 47 | types_tool = getToolByName(self, 'portal_types') |
---|
| 48 | for ptype in types_tool.objectValues(): |
---|
| 49 | if ptype.getId() == 'Folder': |
---|
| 50 | action = ptype.getActionById( 'edit_silo_navigation', default=None ) |
---|
| 51 | if action is None: |
---|
| 52 | out.write( ' Added Silo Navigation tab for %s\n' % ptype.getId() ) |
---|
| 53 | ptype.addAction( 'edit_silo_navigation' |
---|
| 54 | , 'Silo Navigation' |
---|
| 55 | , 'string:${object_url}/silo_navigation_form' |
---|
| 56 | , '' |
---|
| 57 | , 'Modify portal content' |
---|
| 58 | , 'object' |
---|
| 59 | , visible=1 |
---|
| 60 | ) |
---|
| 61 | def removeActions(self): |
---|
| 62 | tool = getToolByName(self, 'portal_types') |
---|
| 63 | for ptype in tool.objectValues(): |
---|
| 64 | if ptype.getId() == 'Folder': |
---|
| 65 | action = ptype.getActionById( 'edit_silo_navigation', default=None ) |
---|
| 66 | if action != None: |
---|
| 67 | acts = list(ptype.listActions()) |
---|
| 68 | ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='edit_silo_navigation']) |
---|
| 69 | |
---|
| 70 | def install(self): |
---|
| 71 | out = StringIO() |
---|
| 72 | |
---|
| 73 | out.write('setupSkin... \n') |
---|
| 74 | setupSkin(self, out, PROJECTNAME) |
---|
| 75 | |
---|
| 76 | installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) |
---|
| 77 | print >> out, 'Type Installed' |
---|
| 78 | |
---|
| 79 | setupActions(self, out) |
---|
| 80 | |
---|
| 81 | return out.getvalue() |
---|
| 82 | |
---|
| 83 | def uninstall(self): |
---|
| 84 | out = StringIO() |
---|
| 85 | |
---|
| 86 | removeActions(self) |
---|
| 87 | |
---|
| 88 | removeSkin(self, PROJECTNAME) |
---|
| 89 | |
---|
| 90 | return out.getvalue() |
---|