# 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 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 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") 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 = ['SchoolDataBase','RegistrationDataBase',] for name in objects: if not hasattr(portal,name.lower()): addObject(portal,name.lower(),name,name) #property for group, mark as practice gd = getToolByName(portal, 'portal_groupdata') if not hasattr(gd,'practice'): safeEditProperty(gd, 'practice', '', 'string') if not hasattr(gd,'deadline'): safeEditProperty(gd, 'deadline', '2006/09/01', 'string') def setupSiteProperties(self, portal): """ Modifies and/or adds properties in portal_properties """ pass def setupInstallProducts(self, portal): """ install any additional products """ prods = ['Eportfolio','COREBlog2'] 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 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