# Copyright 2006 by Meelis Mets """ Eportfolio customization policy for Plone Sites """ __author__ = 'Meelis Mets' from zLOG import INFO, ERROR from Products.Eportfolio.config import GLOBALS, ROLES, PROJECT_NAME 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 from Products.CMFPlone.migrations.migration_util import safeEditProperty, addLinesToProperty import string, types from config import TASK_TYPES, BLOG_TYPES, DRAWER_TYPES from Products.CMFQuickInstallerTool.QuickInstallerTool import AlreadyInstalled 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 setupCatalog(self, portal): """ add a column """ catalog_tool = getToolByName(portal, 'portal_catalog') catalog_tool.manage_addColumn("UID") def setupCompetencyFolder(self, portal): """ adds competency folder """ addObject(portal, 'competency', 'Competencies', 'Competency collection') def setupHelpFolder(self, portal): """ """ from Help import Help addObject(portal, 'help', 'Help', 'Help') def setupPortalTypes(self, portal): """ use portal_factory """ ft = getToolByName(portal, 'portal_factory') types_list = ft.getFactoryTypes() for t in ['BlogEntry', 'Competency', 'Report', 'Drawer', 'QCL', 'EFolder', 'ForumTopicFolder', 'HelpTopic', 'HelpChapter', 'StructuredTemplate', 'Link']+TASK_TYPES: types_list[t] = 1 ft.manage_setPortalFactoryTypes(None, types_list) def setupMemberdata(self, portal): """ Add data for member profile """ md = getToolByName(portal, 'portal_memberdata') if not hasattr(md,'birthday'): safeEditProperty(md, 'birthday', '', 'string') if not hasattr(md,'address1'): safeEditProperty(md, 'address1', '', 'string') if not hasattr(md,'address2'): safeEditProperty(md, 'address2', '', 'string') if not hasattr(md,'town'): safeEditProperty(md, 'town', '', 'string') if not hasattr(md,'county'): safeEditProperty(md, 'county', '', 'string') if not hasattr(md,'postcode'): safeEditProperty(md, 'postcode', '', 'string') if not hasattr(md,'country'): safeEditProperty(md, 'country', '', 'string') if not hasattr(md,'tel'): safeEditProperty(md, 'tel', '', 'string') if not hasattr(md,'mobile'): safeEditProperty(md, 'mobile', '', 'string') if not hasattr(md,'nationality'): safeEditProperty(md, 'nationality', '', 'string') if not hasattr(md,'gender'): safeEditProperty(md, 'gender', '', 'string') if not hasattr(md,'supervisor1'): safeEditProperty(md, 'supervisor1', '', 'string') if not hasattr(md,'supervisor2'): safeEditProperty(md, 'supervisor2', '', 'string') if not hasattr(md,'supervisee'): safeEditProperty(md, 'supervisee', '', 'string') if not hasattr(md,'school'): safeEditProperty(md, 'school', '', 'string') def setupFolder(self, portal): """ Change member folder """ ms = getToolByName(portal, 'portal_membership') ms.setMemberAreaType("Eportfolio") gt = getToolByName(portal, 'portal_groups') gt.groupWorkspacesCreationFlag = 1 gt.manage_setGroupWorkspacesFolder('groupdata') gt.manage_setGroupWorkspaceContainerType('GroupData') gt.manage_setGroupWorkspaceType('Group') 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['Eportfolio'].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 setupPortalProperties(self, portal): """ Sets properties of the portal, such as title. """ #title changing portal.manage_changeProperties(title="Welcome to Eportfolio") #add Basic Objects objects = [] for name in objects: if not hasattr(portal,name.lower()): addObject(portal,name.lower(),name,name) if not hasattr(portal,'groupdata'): addObject(portal,'groupdata','GroupData','Groups') if not hasattr(portal,'schooldatabase'): addObject(portal,'schooldatabase','SchoolDataBase','Schools') #property for group, mark as practice #gd = getToolByName(portal, 'portal_groupdata') #if not hasattr(gd,'hasworksheet'): # safeEditProperty(gd, 'hasworksheet', False, 'boolean') #if not hasattr(gd,'practice'): # safeEditProperty(gd, 'practice', '', 'string') #if not hasattr(gd,'deadline'): # safeEditProperty(gd, 'deadline', '2006/09/01', 'string') pp=getToolByName(portal,'portal_properties') p = getattr(pp , 'navtree_properties', None) if 'Competency' not in p.getProperty('metaTypesNotToList'): addLinesToProperty(p, 'metaTypesNotToList', 'Competency') 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_eportfolio/macros/portlet', 'here/portlet_navigation/macros/portlet')) def setupSiteActionProperties(self, portal): """ Change some portal actions and their properties. """ # this code goes into portal_actions, searches for full_screen and sets its visibility to 0 pa=getToolByName(portal, 'portal_actions') _actions=pa._cloneActions() for action in _actions: if action.id=='full_screen': action.visible=0 pa._actions=_actions if action.id=='sendto': action.visible=0 pa._actions=_actions # this code goes into portal_undo, searches for undo and sets its visibility to 0 pu=getToolByName(portal, 'portal_undo') _actions=pu._cloneActions() for action in _actions: if action.id=='undo': action.visible=0 pu._actions=_actions # this code goes into portal_membership, searches for mystyff and chenges the title to My portfolio from Products.CMFCore.Expression import Expression pm=getToolByName(portal, 'portal_membership') _actions=pm._cloneActions() for action in _actions: if action.id=='mystuff': action.title='My portfolio' action.action=Expression('string:${portal/portal_membership/getHomeUrl}/dashboard') pm._actions=_actions def setupInstallProducts(self, portal): """ install any additional products """ prods = ['Eportfolio',] qi = getToolByName(portal, 'portal_quickinstaller', None) for x in prods: try: qi.installProduct(x) except AlreadyInstalled: pass def setup002Workflows(self, portal): """Setup custom workflows.""" wtool = getToolByName(portal, 'portal_workflow') for workflow in ['task_workflow', 'simple_workflow']: try: wtool.manage_delObjects(workflow) except: pass wtool.manage_addWorkflow('task_workflow (Eportfolio task workflow)', 'task_workflow') wtool.setChainForPortalTypes(BLOG_TYPES+TASK_TYPES+DRAWER_TYPES, 'task_workflow') wtool.manage_addWorkflow('simple_workflow (Eportfolio simple workflow)', 'simple_workflow') wtool.setChainForPortalTypes(('StructuredTemplate',), 'simple_workflow') #wtool.updateRoleMappings() def setupCalendar(self, portal): """ """ if hasattr(portal, 'portal_calendar'): portal._delObject('portal_calendar') #if not hasattr(self, 'portal_calendar'): addTool = portal.manage_addProduct[PROJECT_NAME].manage_addTool #Add the tool by its meta_type addTool('CalendarTool') # calTool = getToolByName(portal, 'portal_calendar') # calTool.calendar_types = ('Event', 'BlogEntry', 'ReflectionTask', 'StructuredTask') # calTool.calendar_states = ('published', 'public') # import calendar # calendar.setfirstweekday(0) #start day Mon(0)-Sun(6) def setupaddActions(self, portal): """adding some actions""" tool = getToolByName(portal, 'portal_types') fileinfo = tool.getTypeInfo('File') idx = 0 for action in fileinfo.listActions(): if action.getId() == 'delete' or action.getId() == 'Competency': fileinfo.deleteActions((idx,)) idx -= 1 idx += 1 fileinfo.addAction( id='delete' , name='Delete' , action='string:${object_url}/delete_confirmation' , condition='' , permission=('Modify portal content',) , category='object' , visible=1 ) fileinfo.addAction( id='Competency' , name='Associate with competency' , action='string:${object_url}/add_reference_to_competency?uid=${object/UID}' , condition='' , permission=('Modify portal content',) , category='object' , visible=1 ) imagefileinfo = tool.getTypeInfo('Image') idx = 0 for action in imagefileinfo.listActions(): if action.getId() == 'delete' or action.getId() == 'Competency': imagefileinfo.deleteActions((idx,)) idx -= 1 idx += 1 imagefileinfo.addAction( id='delete' , name='Delete' , action='string:${object_url}/delete_confirmation' , condition='' , permission=('Modify portal content',) , category='object' , visible=1 ) imagefileinfo.addAction( id='Competency' , name='Associate with competency' , action='string:${object_url}/add_reference_to_competency?uid=${object/UID}' , condition='' , permission=('Modify portal content',) , category='object' , visible=1 ) # 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 EportfolioSetup(SetupWidget): type = 'Eportfolio Setup' description = """Customization methods needed by the Eportfolio 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