# Copyright 2005 by Meelis Mets """ Krihvell customization policy for Plone Sites """ __author__ = 'Meelis Mets' from zLOG import INFO, ERROR from Products.Krihvel.config import GLOBALS, ROLES, SKINLIST from Products.Archetypes.Extensions.utils import install_subskin from Products.CMFCore.utils import getToolByName from Products.CMFCore.DirectoryView import registerDirectory, addDirectoryViews from Products.CMFPlone.migrations.migration_util import safeEditProperty from zExceptions import BadRequest def installPortalTools(self, portal): """Add any necessary portal tools""" out = [] install_subskin(portal, out, GLOBALS) def installPortalSkins(self, portal): """ Installs skins """ sk_tool = portal.portal_skins registerDirectory('styles', GLOBALS) addDirectoryViews( sk_tool, 'styles', GLOBALS) for skin in SKINLIST: path = [elem.strip() for elem in \ sk_tool.getSkinPath('Plone Default').split(',')] path.insert(path.index('custom')+1, skin) sk_tool.addSkinSelection(skin, ','.join(path)) def addObject(portal,id,type,title,desc=None,view=None,own=None): """Convenience method for creating new content items.""" try: # Creating object portal.manage_addProduct['Krihvel'].manage_addContent(type=type, id=id) #getting objects info ob=getattr(portal,id) # Set Title ob.setTitle(title) # Publish content - broken!!! #ob.content_status_modify(workflow_action='publish') except BadRequest: # If the id already existed, we'll just quietly be happy about it. pass def setPortalProperties(self, portal): """ Sets properties of the portal, such as title. """ #title changing portal.manage_changeProperties(title="Welcome to Krihvel") #add data for groups if portal.portal_groupdata.getProperty('klass', 0): portal.portal_groupdata.manage_addProperty('klass',0,'boolean') if portal.portal_groupdata.getProperty('grupp', 0): portal.portal_groupdata.manage_addProperty('grupp',0,'boolean') #add data for members if portal.portal_memberdata.getProperty('birthday', 0): portal.portal_memberdata.manage_addProperty('birthday','01.01.1990','string') #add Basic Objects objects = ['TaskCollector', 'GradeBook', 'Exhibition'] for name in objects: addObject(portal,name.lower(),name,name) def setFolder(self, portal): """ Change member folder """ ms = getToolByName(portal, 'portal_membership') ms.setMemberAreaType("MyFolder") def setSiteProperties(self, portal): """ Modifies and/or adds properties in portal_properties """ #adding portlet_menu, keeping portlet_navigation removing others from left_slots safeEditProperty(portal,'left_slots',('here/portlet_enter/macros/portlet', 'here/portlet_tools/macros/portlet', 'here/portlet_navigation/macros/portlet')) #removing all portlets from right_slots safeEditProperty(portal,'right_slots',('', )) def installPortalRoles(self, portal): """ adds roles. creates groups """ out = [] for x in ROLES: portal._addRole(x) def installProducts(self, portal): """ install any additional products """ prods = ['Krihvel',] qi = getToolByName(portal, 'portal_quickinstaller', None) for x in prods: qi.installProduct(x) functions = { 'installPortalSkins': installPortalSkins, 'setPortalProperties': setPortalProperties, 'setFolder': setFolder, 'setSiteProperties': setSiteProperties, 'installProducts': installProducts, 'installPortalRoles': installPortalRoles, 'installPortalTools': installPortalTools, } class KrihvelSiteSetup: type = 'Krihvel Setup' description = "Krihvel Policy." functions = functions single = 0 # huh!? def __init__(self, portal): self.portal = portal def setup(self): pass def delItems(self, fns): out = [] out.append(('no way to remove function', INFO)) return out def addItems(self, fns): out = [] for fn in fns: self.functions[fn](self, self.portal) out.append(('Function %s has been applied' % fn, INFO)) return out def active(self): return 1 def installed(self): return [] def available(self): """ functions """ return self.functions.keys()