# Copyright 2007 by Meelis Mets """ Psyhvel customization policy for Plone Sites """ __author__ = 'Meelis Mets' from zLOG import INFO, ERROR from Products.Psyhvel.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 from config import STIMULUS_LIST, TASK_LIST, TEST_LIST 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) portal.acl_users.addRole(x) def setupFolder(self, portal): """ member folder """ ms = getToolByName(portal, 'portal_membership') #we need member folders now #ms.memberareaCreationFlag = 0 ms.setMemberAreaType("UserFolder") 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['Psyhvel'].manage_addContent(type=type, id=id) #getting objects info ob=getattr(portal,id) # Set Title ob.setTitle(title) ob.reindexObject() # 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 setupFrontPage(self,portal): """Setup the front page.""" # Make sure that old PythonScript for redirecting isn't there anymore # the content section. try: portal._delObject('front-page') except AttributeError: pass def setupPortalProperties(self, portal): """ Sets properties of the portal, such as title. """ #title changing portal.manage_changeProperties(title="PSYHVEL") #add data for members md = getToolByName(portal, 'portal_memberdata') if not hasattr(md,'birthday'): safeEditProperty(md, 'birthday', '01.01.1990', 'string') if not hasattr(md,'sex'): safeEditProperty(md, 'sex', 'Girl', 'string') #add Basic Objects objects = ['Psyhvel',] for name in objects: addObject(portal,name.lower(),name,name) def setupSiteProperties(self, portal): """ Modifies and/or adds properties in portal_properties """ safeEditProperty(portal,'default_page','psyhvel') #adding portlet_menu, keeping portlet_navigation removing others from left_slots safeEditProperty(portal,'left_slots',( 'here/portlet_navigation/macros/portlet', )) #removing all portlets from right_slots safeEditProperty(portal,'right_slots',('', )) pass def setupInstallProducts(self, portal): """ install any additional products """ prods = ['Psyhvel',] qi = getToolByName(portal, 'portal_quickinstaller', None) for x in prods: qi.installProduct(x) def setup002Workflows(self, portal): """Setup custom workflows.""" wtool = getToolByName(portal, 'portal_workflow') for workflow in ['psyhvel_workflow']: try: wtool.manage_delObjects(workflow) except: pass wtool.manage_addWorkflow('psyhvel_workflow (Psyhvel workflow)', 'psyhvel_workflow') wtool.setChainForPortalTypes(STIMULUS_LIST+TASK_LIST+TEST_LIST, 'psyhvel_workflow') wtool.updateRoleMappings() def setupPsyhvelZipActions(self, portal): at = getToolByName(portal, 'portal_actions') at.addAction('export', name='Export', action='string:makeZipExport:method', condition='here/isExportable | nothing', permission='Modify portal content', category='folder_buttons') at.addAction('import', name='Import', action='string:import_form:method', condition='here/isImportable | nothing', permission='Modify portal content', category='folder_buttons') at.addAction(id='import_action', name='Import', action='string:import_form', permission='Modify portal content', condition='here/isImportable | nothing', category='object_buttons' ) at.addAction(id='export_action', name='Export', action='string:makeZipExport', permission='Modify portal content', condition='here/isExportable | nothing', category='object_buttons' ) def setupCleanDuplicateActions(self, portal): atool=getToolByName(portal, 'portal_actions') acts = atool._cloneActions() clean_acts=[] home_check = ownership_check = rename_check = paste_check = delete_check = cut_check = copy_check = 0 for a in acts: if a.getId()=='index_html': #'Home' if home_check==0: home_check=1 clean_acts.append(a) elif a.getId()=='change_ownership': if ownership_check==0: ownership_check=1 clean_acts.append(a) elif a.getId()=='rename': if rename_check==0: rename_check=1 clean_acts.append(a) elif a.getId()=='paste': if paste_check==0: paste_check=1 clean_acts.append(a) elif a.getId()=='cut': if cut_check==0: copy_check=1 clean_acts.append(a) elif a.getId()=='copy': if copy_check==0: copy_check=1 clean_acts.append(a) elif a.getId()=='delete': if delete_check==0: delete_check=1 clean_acts.append(a) elif a.getId()=='import': if delete_check==0: delete_check=1 clean_acts.append(a) elif a.getId()=='export': if delete_check==0: delete_check=1 clean_acts.append(a) elif a.getId()=='import_action': if delete_check==0: delete_check=1 clean_acts.append(a) elif a.getId()=='export_action': if delete_check==0: delete_check=1 clean_acts.append(a) else: clean_acts.append(a) atool._actions = tuple( clean_acts ) mtool=getToolByName(portal, 'portal_membership') acts = mtool._cloneActions() clean_acts=[] check = 0 for a in acts: if a.getId()=='myworkspace': if not check: check=1 clean_acts.append(a) else: clean_acts.append(a) mtool._actions = tuple( clean_acts ) ######### # 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 PsyhvelSetup(SetupWidget): type = 'Psyhvel Setup' description = """Customization methods needed by the Psyhvel 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