/
factory.py
57 lines (46 loc) · 1.93 KB
/
factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.CMFCore.utils import getToolByName
from Products.GenericSetup.tool import SetupTool
from Portal import PloneSite
from utils import WWW_DIR
_TOOL_ID = 'portal_setup'
def addPloneSiteForm(dispatcher):
"""
Wrap the PTF in 'dispatcher'.
XXX improve addSite.zpt to handle alternate base and extension policies,
provided by this method. (need to only show Plone-specific ones.)
"""
wrapped = PageTemplateFile('addSite', WWW_DIR).__of__(dispatcher)
return wrapped()
def addPloneSite(dispatcher, id, title='', description='',
create_userfolder=1, email_from_address='',
email_from_name='', validate_email=0,
profile_id='CMFPlone:plone', snapshot=False,
RESPONSE=None, extension_ids=()):
""" Add a PloneSite to 'dispatcher', configured according to 'profile_id'.
"""
site = PloneSite(id)
dispatcher._setObject(id, site)
site = dispatcher._getOb(id)
site._setObject(_TOOL_ID, SetupTool(_TOOL_ID))
setup_tool = getToolByName(site, _TOOL_ID)
setup_tool.setImportContext('profile-%s' % profile_id)
setup_tool.runAllImportSteps()
for extension_id in extension_ids:
setup_tool.setImportContext('profile-%s' % extension_id)
setup_tool.runAllImportSteps()
setup_tool.setImportContext('profile-%s' % profile_id)
props = {}
prop_keys = ['title', 'description', 'email_from_address',
'email_from_name', 'validate_email']
loc_dict = locals()
for key in prop_keys:
if loc_dict[key]:
props[key] = loc_dict[key]
if props:
site.manage_changeProperties(**props)
if snapshot is True:
setup_tool.createSnapshot('initial_configuration')
if RESPONSE is not None:
RESPONSE.redirect('%s/manage_main?update_menu=1'
% dispatcher.absolute_url())