# Copyright 2006 by Meelis Mets """ Krihvel customization policy for Plone Sites """ __author__ = 'Meelis Mets' from zLOG import INFO, ERROR from Products.Krihvel.config import GLOBALS, ROLES 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 from Products.CMFPlone.setup.SetupBase import SetupWidget import string, types def setupInstallPortalTools(self, portal): """Add any necessary portal tools""" out = [] install_subskin(portal, out, GLOBALS) def setupInstallPortalRoles(self, portal): """ adds roles. creates groups """ out = [] for x in ROLES: portal._addRole(x) def setupFolder(self, portal): """ Change member folder """ ms = getToolByName(portal, 'portal_membership') ms.setMemberAreaType("MyFolder") 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 setupPortalProperties(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', 'LinkCollector','Gallery'] for name in objects: addObject(portal,name.lower(),name,name) def setupSiteProperties(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 setupInstallProducts(self, portal): """ install any additional products """ prods = ['Krihvel',] qi = getToolByName(portal, 'portal_quickinstaller', None) for x in prods: qi.installProduct(x) ######### # Collect all setup functions into a setup widget afunctions = {} for f in dir(): if f.startswith('setup'): func = eval("%s" % f) if type(func) == types.FunctionType: afunctions[f] = func class KrihvelSetup(SetupWidget): type = 'Krihvel Setup' description = """Customization methods needed by the Krihvel Plone portal""" functions = afunctions def setup(self): pass def delItems(self, fns): out = [] out.append(('Currently there is no way to remove a function', INFO)) return out def addItems(self, fns): """This method is called when configuration methods need to be applied. fns is the list of function names that need to be executed in order.""" out = [] for fn in fns: # All functions are executed with the portal as the first actual parameter self.functions[fn](self, self.portal) out.append(('Function %s has been applied' % fn, INFO)) return out def installed(self): return [] def available(self): """Get a list of availabel functions.""" funcs = self.functions.keys() # Sort, so we get a pre-determined order. # The functions need to be named properly funcs.sort() return funcs