[1] | 1 | import string |
---|
| 2 | from cStringIO import StringIO |
---|
| 3 | from Products.CMFCore.utils import getToolByName |
---|
| 4 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
| 5 | |
---|
| 6 | from Products.geolocation.config import * |
---|
| 7 | |
---|
| 8 | PORTAL_TYPES = ['Document', 'News Item', 'Event', 'Link', 'Image'] |
---|
| 9 | |
---|
| 10 | def setupSkin(self, out, skinFolder): |
---|
| 11 | """ Setup product skin layer """ |
---|
| 12 | skinstool=getToolByName(self, 'portal_skins') |
---|
| 13 | addDirectoryViews(skinstool, SKINS_DIR, GLOBALS) |
---|
| 14 | for skin in skinstool.getSkinSelections(): |
---|
| 15 | path = skinstool.getSkinPath(skin) |
---|
| 16 | path = map(string.strip, string.split(path,',')) |
---|
| 17 | if not skinFolder in path: |
---|
| 18 | try: |
---|
| 19 | path.insert( path.index('custom')+1, skinFolder) |
---|
| 20 | except ValueError: |
---|
| 21 | path.append(skinFolder) |
---|
| 22 | path = string.join(path, ', ') |
---|
| 23 | skinstool.addSkinSelection(skin, path) |
---|
| 24 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 25 | else: |
---|
| 26 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
---|
| 27 | |
---|
| 28 | def removeSkin(self, skins=[]): |
---|
| 29 | """ Setup product skin layer """ |
---|
| 30 | if skins: |
---|
| 31 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 32 | for skinName in skinstool.getSkinSelections(): |
---|
| 33 | path = skinstool.getSkinPath(skinName) |
---|
| 34 | path = [i.strip() for i in path.split(',')] |
---|
| 35 | for s in skins: |
---|
| 36 | if s in path: |
---|
| 37 | path.remove(s) |
---|
| 38 | s += '/' |
---|
| 39 | for layer in path: |
---|
| 40 | if layer.startswith(s): |
---|
| 41 | path.remove(layer) |
---|
| 42 | path = ','.join(path) |
---|
| 43 | skinstool.addSkinSelection(skinName, path) |
---|
| 44 | |
---|
| 45 | def installGEOLocationAction(self): |
---|
| 46 | """ add geoLocation edit tab for content types """ |
---|
| 47 | ptypes = getToolByName(self, 'portal_types') |
---|
| 48 | for tname in PORTAL_TYPES: |
---|
| 49 | type = ptypes.getTypeInfo(tname) |
---|
| 50 | type.addAction('edit_location', |
---|
| 51 | name='GEO Location', |
---|
| 52 | action='string:edit_location', |
---|
| 53 | condition='', |
---|
| 54 | permission='Modify portal content', |
---|
| 55 | category='object') |
---|
| 56 | |
---|
| 57 | def uninstallGEOLocationAction(self): |
---|
| 58 | """ remove geoLocation edit tab for content types """ |
---|
| 59 | ptypes = getToolByName(self, 'portal_types') |
---|
| 60 | for tname in PORTAL_TYPES: |
---|
| 61 | type = ptypes.getTypeInfo(tname) |
---|
| 62 | actions = type._cloneActions() |
---|
| 63 | actions = [a for a in actions if a.id != 'edit_location'] |
---|
| 64 | type._actions = tuple(actions) |
---|
| 65 | |
---|
| 66 | def install(self): |
---|
| 67 | """ Product installation """ |
---|
| 68 | out = StringIO() |
---|
| 69 | out.write('setupSkin... \n') |
---|
| 70 | setupSkin(self, out, PROJECTNAME) |
---|
| 71 | catalog = getToolByName(self, 'portal_catalog') |
---|
| 72 | if 'geoLocation' not in catalog.indexes(): |
---|
| 73 | catalog.addIndex('geoLocation','FieldIndex') |
---|
| 74 | if 'geoLocation' not in catalog.schema(): |
---|
| 75 | catalog.addColumn('geoLocation') |
---|
| 76 | out.write('geoLocation index created') |
---|
| 77 | installGEOLocationAction(self) |
---|
| 78 | out.write('Added geolocation edit for content types') |
---|
| 79 | return out.getvalue() |
---|
| 80 | |
---|
| 81 | def uninstall(self): |
---|
| 82 | out = StringIO() |
---|
| 83 | removeSkin(self, [PROJECTNAME,]) |
---|
| 84 | uninstallGEOLocationAction(self) |
---|
| 85 | out.write('Removed geolocation edit for content types') |
---|