source: trunk/ConfigurationMethods.py @ 56

Revision 56, 7.3 KB checked in by laszlo, 14 years ago (diff)

fixes #147 spent 1h

  • Property svn:eol-style set to LF
Line 
1# -*- coding: iso-8859-1 -*-
2
3from Acquisition import aq_get
4from AccessControl import Permissions
5from zExceptions import BadRequest
6from OFS.PropertyManager import PropertyManager
7from zLOG import INFO, ERROR
8
9from Products.CMFCore.utils import getToolByName
10from Products.CMFCore import CMFCorePermissions
11from Products.CMFCore.Expression import Expression
12from Products.CMFCore.utils import getToolByName
13from Products.CMFCore.DirectoryView import registerDirectory, addDirectoryViews
14from Products.CMFCore.ActionInformation import ActionInformation
15from Products.CMFPlone.migrations.migration_util import safeEditProperty
16from Products.CMFPlone.PloneFolder import addPloneFolder
17from Products.CMFPlone.setup.SetupBase import SetupWidget
18from Products.SiteErrorLog.SiteErrorLog import manage_addErrorLog
19from Products.Archetypes.public import listTypes, registerType
20from Products.Archetypes.Extensions.utils \
21     import installTypes, install_subskin
22
23from DateTime import DateTime
24import string, types
25from cStringIO import StringIO
26
27from config import *
28from ToolboxMember import userproperties
29
30# All methods starting with "setup" will be used in the customization policy
31# The methods will be sorted by ascii value, so if something  needs to happen before
32# something else, make it so (see method setup001Dependencies).
33
34# Note that all methods need to be repeatable - they should not fail
35# if they are run again when all that they do has already been done.
36# Also, the methods should be able to upgrade, meaning that older customizations
37# should be changed to match the newest specifications.
38
39def setup001Dependencies(self, portal):
40    """Install all necessary products into the plone instance."""
41    qi=getToolByName(portal, 'portal_quickinstaller')
42    # We need ourselves installed into the plone instance,
43    # since we provide portal tools and content
44    qi.installProduct('Toolbox')
45
46def setupSkin(self,portal):
47    """Create new custom skin."""
48    skinsTool = getToolByName(portal,"portal_skins")
49
50    # Register our own skin folder as a viewable folder
51    try:
52        addDirectoryViews(skinsTool,SKINS_DIR,GLOBALS)
53    except:
54        # If the directory is already registered, we just continue
55        pass
56
57    # Create our new skin, making it a copy of BASE_SKIN and adding
58    # our skin layer just after "custom".
59    if SKIN_NAME not in skinsTool.getSkinSelections():
60        path = skinsTool.getSkinPath(BASE_SKIN)
61        path = map(string.strip,string.split(path,','))
62        for skinFolder in SKIN_FOLDERS:
63            if skinFolder not in path:
64                try:
65                    path.insert(path.index('custom')+1,skinFolder)
66                except ValueError:
67                    path.append(skinFolder)
68        path=string.join(path,',')
69        skinsTool.addSkinSelection(SKIN_NAME,path)
70
71    # Select our new skin as default
72    skinsTool.default_skin=SKIN_NAME
73
74def addObject(portal,id,type,title,desc=None,view=None,own=None):
75    """Convenience method for creating new content items."""
76    try:
77        portal.invokeFactory(id=id,type_name=type)
78    except BadRequest:
79        # If the id already existed, we'll just quietly be happy about it.
80        pass
81    finalizeObject(portal,id,title,desc,view,own)
82
83def finalizeObject(portal,id,title,desc=None,view=None,own=None):
84    """Set content object properties in place."""
85    ob=getattr(portal,id)
86   
87    # Set basic properties of object
88    ob.setTitle(to_unicode(title))
89    if desc:
90        ob.setDescription(to_unicode(desc))
91       
92    # Publish content
93    ob.content_status_modify(workflow_action='publish')
94
95def setupFolders(self,portal):
96    """Setup the basic structure of the site."""
97    atool = getToolByName(portal, 'portal_actions')
98    acts = atool._cloneActions()
99
100    # Loop through all main sections
101    for item in SECTIONS:
102        # Create folder
103        addObject(portal,item.lower(),'Folder',item)
104        flag = False
105        for action in acts:
106            if action.category == 'portal_tabs' and action.title == item:
107                flag = True
108        if not flag:
109            # Add action for portal tab
110            acts.append(ActionInformation(id=item.lower(),
111                                      title=item,
112                                      description=item,
113                                      category='portal_tabs',
114                                      permissions=('View',),
115                                      visible=True,
116                                      action='string:$portal_url/%s' % item.lower()))
117    atool._actions=acts
118
119
120def setupToptabs(self,portal):
121    # Disable automatic tabs for top level folders
122    stp = getToolByName(portal,'portal_properties').site_properties
123    safeEditProperty(stp,'disable_folder_sections',True)
124
125    # Hide all tabs that aren't what we want
126    atool = getToolByName(portal, 'portal_actions')
127    # Hide all tabs that aren't needed
128    for a in atool._actions:
129        if a.getCategory() in ('portal_tabs',):
130            # Don't hide the tabs that we've created (specified in "SECTIONS")
131            if a.Title() not in SECTIONS:
132                a.visible=0
133
134
135def setupPortlets(self,portal):
136    """Sets up the basic portlet layout."""
137
138    # Use safeEditProperty always to edit properties of the portal or any tools
139    safeEditProperty(portal,'left_slots',('here/portlet_login/macros/portlet',
140                                          'here/portlet_related/macros/portlet'))
141    safeEditProperty(portal,'right_slots',('here/portlet_review/macros/portlet',
142                                           'here/portlet_news/macros/portlet',
143                                           'here/portlet_events/macros/portlet'))
144
145def setupSiteSyndication(self, portal):
146    # Enable syndication
147    syn_tool = getToolByName(portal, 'portal_syndication')
148    syn_tool.editProperties(isAllowed=True)
149    #safeEditProperty(syn_tool,'isAllowed',True)
150
151
152def setupUsers(self,portal):
153    mdat_tool = getToolByName(portal, 'portal_memberdata')
154    for prop in userproperties:
155        mdat_tool.manage_addProperty(prop,'','lines')
156
157#########
158# Collect all setup functions into a setup widget
159
160afunctions = {}
161
162for f in dir():
163    if f.startswith('setup'):
164        func = eval("%s" % f)
165        if type(func) == types.FunctionType:
166            afunctions[f] = func
167
168class ToolboxSetup(SetupWidget):
169    type = 'Toolbox Setup'
170
171    description = """Customization methods needed by the Toolbox Plone portal"""
172
173    functions = afunctions
174
175    def setup(self):
176        pass
177
178    def delItems(self, fns):
179        out = []
180        out.append(('Currently there is no way to remove a function', INFO))
181        return out
182
183    def addItems(self, fns):
184        """This method is called when configuration methods need to be applied.
185        fns is the list of function names that need to be executed in order."""
186        out = []
187        for fn in fns:
188            # All functions are executed with the portal as the first actual parameter
189            self.functions[fn](self, self.portal)
190            out.append(('Function %s has been applied' % fn, INFO))
191        return out
192
193    def installed(self):
194        return []
195
196    def available(self):
197        """Get a list of availabel functions."""
198        funcs = self.functions.keys()
199        # Sort, so we get a pre-determined order.
200        # The functions need to be named properly
201        funcs.sort()
202        return funcs
203
Note: See TracBrowser for help on using the repository browser.