from Acquisition import aq_get from AccessControl import Permissions, getSecurityManager from zExceptions import BadRequest from OFS.PropertyManager import PropertyManager from zLOG import INFO, ERROR from Products.CMFCore.utils import getToolByName from Products.CMFCore.DirectoryView import registerDirectory, addDirectoryViews from Products.CMFCore.ActionInformation import ActionInformation from Products.CMFPlone.migrations.migration_util import safeEditProperty from Products.CMFPlone.PloneFolder import addPloneFolder from Products.CMFPlone.setup.SetupBase import SetupWidget from Products.SiteErrorLog.SiteErrorLog import manage_addErrorLog from Products.Archetypes.public import listTypes, registerType from Products.Archetypes.Extensions.utils import installTypes, install_subskin from Products.PythonScripts.PythonScript import PythonScript from DateTime import DateTime import string, types from cStringIO import StringIO from config import * def setupSkin(self,portal): """Create new custom skin.""" skinsTool = getToolByName(portal,"portal_skins") # Register our own skin folder as a viewable folder try: addDirectoryViews(skinsTool,SKINS_DIR,GLOBALS) except: # If the directory is already registered, we just continue pass # Create our new skin, making it a copy of BASE_SKIN and adding # our skin layer just after "custom". for SKIN_NAME in SKIN_NAMES: if SKIN_NAME not in skinsTool.getSkinSelections(): path = skinsTool.getSkinPath(BASE_SKIN) path = map(string.strip,string.split(path,',')) for skinFolder in SKIN_COMMON_FOLDERS + [SKIN_NAME.lower().replace(' ','_'),]: if skinFolder not in path: try: path.insert(path.index('custom')+1,skinFolder) except ValueError: path.append(skinFolder) path=string.join(path,',') skinsTool.addSkinSelection(SKIN_NAME,path) # Select our first skin as default skinsTool.default_skin=SKIN_NAMES[0] def setupTabs(self, portal): """ Create tabs """ atool = getToolByName(portal, 'portal_actions') acts = atool._cloneActions() new_acts=[] for action in acts: if action.category == 'portal_tabs': pass else: new_acts.append(action) for tab in TABS: id = tab[0] cat = tab[1] title = tab[2] action = tab[3] if not action: action = 'string:$portal_url/%s' % id new_acts.append(ActionInformation( id=id, title=title, description=id, category=cat, permissions=('View',), visible=True, action=action)) # create folder if not hasattr(portal, id): addObject(portal, id, 'Folder', title) atool._actions = new_acts def setupProperties(self, portal): """ set properties """ pp = getToolByName(portal, 'portal_properties') pp.site_properties.manage_changeProperties(disable_folder_sections=True) # portlets safeEditProperty(portal, 'left_slots', ('here/portlet_navigation/macros/portlet', 'here/portlet_recent/macros/portlet', 'here/portlet_related/macros/portlet', 'here/portlet_logos/macros/portlet')) safeEditProperty(portal, 'right_slots', ( 'here/portlet_review/macros/portlet', 'here/portlet_news/macros/portlet', 'here/portlet_events/macros/portlet', 'here/portlet_calendar/macros/portlet',)) def addObject(portal,id,type,title,desc=None): """Convenience method for creating new content items.""" try: portal.invokeFactory(id=id,type_name=type) except BadRequest: # If the id already existed, we'll just quietly be happy about it. pass finalizeObject(portal,id,title,desc) def finalizeObject(portal,id,title,desc=None): """Set content object properties in place.""" ob=getattr(portal,id) # Set basic properties of object ob.setTitle(to_unicode(title)) if desc: ob.setDescription(to_unicode(desc)) # Publish content ob.content_status_modify(workflow_action='publish') ######### # 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 KoolieluSetup(SetupWidget): type = 'Koolielu Setup' description = """Koolielu customization""" 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