Back to index

plone3  3.1.7
factory.py
Go to the documentation of this file.
00001 from zope.component import getAllUtilitiesRegisteredFor
00002 from zope.interface import implements
00003 
00004 from Products.GenericSetup.interfaces import ISetupTool
00005 from Products.GenericSetup.tool import SetupTool
00006 from Products.GenericSetup import profile_registry
00007 from Products.GenericSetup import BASE, EXTENSION
00008 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00009 
00010 from Portal import PloneSite
00011 from utils import WWW_DIR
00012 from interfaces import INonInstallable
00013 from interfaces import IPloneSiteRoot
00014 
00015 _TOOL_ID = 'portal_setup'
00016 _DEFAULT_PROFILE = 'Products.CMFPlone:plone'
00017 
00018 
00019 class HiddenProfiles(object):
00020     implements(INonInstallable)
00021 
00022     def getNonInstallableProfiles(self):
00023         return [u'Products.Archetypes:Archetypes',
00024                 u'Products.CMFDiffTool:CMFDiffTool',
00025                 u'Products.CMFEditions:CMFEditions',
00026                 u'Products.CMFFormController:CMFFormController',
00027                 u'Products.CMFQuickInstallerTool:CMFQuickInstallerTool',
00028                 u'Products.MimetypesRegistry:MimetypesRegistry',
00029                 u'Products.PortalTransforms:PortalTransforms',
00030                 u'Products.PloneLanguageTool:PloneLanguageTool',
00031                 u'Products.PlonePAS:PlonePAS',
00032                 u'plone.browserlayer:default',
00033                 u'plone.portlet.static:default',
00034                 u'plone.portlet.collection:default',
00035                 u'kupu:default',
00036                 u'Products.CMFPlone:dependencies',
00037                 ]
00038 
00039 
00040 def addPloneSiteForm(dispatcher):
00041     """
00042     Wrap the PTF in 'dispatcher'.
00043     """
00044     wrapped = PageTemplateFile('addSite', WWW_DIR).__of__(dispatcher)
00045 
00046     base_profiles = []
00047     extension_profiles = []
00048     not_installable = []
00049 
00050     utils = getAllUtilitiesRegisteredFor(INonInstallable)
00051     for util in utils:
00052         not_installable.extend(util.getNonInstallableProfiles())
00053 
00054     for info in profile_registry.listProfileInfo():
00055         if info.get('type') == EXTENSION and \
00056            info.get('for') in (IPloneSiteRoot, None):
00057             if info.get('id') not in not_installable:
00058                 extension_profiles.append(info)
00059 
00060     for info in profile_registry.listProfileInfo():
00061         if info.get('type') == BASE and \
00062            info.get('for') in (IPloneSiteRoot, None):
00063             if info.get('id') not in not_installable:
00064                 base_profiles.append(info)
00065 
00066     return wrapped(base_profiles=tuple(base_profiles),
00067                    extension_profiles=tuple(extension_profiles),
00068                    default_profile=_DEFAULT_PROFILE)
00069 
00070 def addPloneSite(dispatcher, id, title='', description='',
00071                  create_userfolder=1, email_from_address='',
00072                  email_from_name='', validate_email=0,
00073                  profile_id=_DEFAULT_PROFILE, snapshot=False,
00074                  RESPONSE=None, extension_ids=()):
00075     """ Add a PloneSite to 'dispatcher', configured according to 'profile_id'.
00076     """
00077     site = PloneSite(id)
00078     dispatcher._setObject(id, site)
00079     site = dispatcher._getOb(id)
00080 
00081     site._setObject(_TOOL_ID, SetupTool(_TOOL_ID))
00082     setup_tool = getattr(site, _TOOL_ID)
00083 
00084     setup_tool.setBaselineContext('profile-%s' % profile_id)
00085     setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)
00086     for extension_id in extension_ids:
00087         setup_tool.runAllImportStepsFromProfile('profile-%s' % extension_id)
00088 
00089     props = {}
00090     prop_keys = ['title', 'description', 'email_from_address',
00091                  'email_from_name', 'validate_email']
00092     loc_dict = locals()
00093     for key in prop_keys:
00094         if loc_dict[key]:
00095             props[key] = loc_dict[key]
00096     if props:
00097         site.manage_changeProperties(**props)
00098 
00099     if snapshot is True:
00100         setup_tool.createSnapshot('initial_configuration')
00101 
00102     if RESPONSE is not None:
00103         RESPONSE.redirect('%s/manage_main?update_menu=1'
00104                          % dispatcher.absolute_url())