# 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 """ for x in ROLES: portal._addRole(x) portal.acl_users.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 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 if action.id=='print': 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 def setupPortalProperties(self, portal): """ Sets properties of the portal, such as title. """ #title changing portal.manage_changeProperties(title="ÕPIKESKKOND KRIHVEL") #intro flash movie portal.manage_addProperty('showIntroMovie',0,'boolean') #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 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 = ['TaskCollector', 'GradeBook', 'ExhibitionFolder', 'LinkCollector','Gallery','Help','Chat'] for name in objects: addObject(portal,name.lower(),name,name) def setupPortalTypes(self, portal): """ use portal_factory """ ft = getToolByName(portal, 'portal_factory') types_list = ft.getFactoryTypes() for t in ['BaseTask','Crossword','Paper','Pairs', 'WordMap', 'ImageEditorRaster','FillIn','Math','KFolder','Gallery','Exhibition','LinkItem','Image']: types_list[t] = 1 ft.manage_setPortalFactoryTypes(None, types_list) pt = getToolByName(portal, 'portal_types') for type_id in ['Image']: ti = pt.getTypeInfo(type_id) if ('allow_discussion' in ti.propertyIds()): ti.manage_changeProperties(allow_discussion=1) def setupSiteProperties(self, portal): """ Modifies and/or adds properties in portal_properties """ safeEditProperty(portal,'default_page','help') #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','PloneChat'] 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