Back to index

plone3  3.1.7
factory.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Configured site factory implementation.
00014 
00015 $Id: factory.py 77113 2007-06-26 20:36:26Z yuppie $
00016 """
00017 
00018 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00019 from zope.app.component.hooks import setSite
00020 
00021 from Products.CMFCore.interfaces import ISiteRoot
00022 from Products.CMFCore.utils import getToolByName
00023 from Products.GenericSetup import EXTENSION
00024 from Products.GenericSetup import profile_registry
00025 from Products.GenericSetup.tool import SetupTool
00026 
00027 from Portal import CMFSite
00028 from utils import _wwwdir
00029 
00030 _TOOL_ID = 'portal_setup'
00031 
00032 
00033 def addConfiguredSiteForm(dispatcher):
00034     """ Wrap the PTF in 'dispatcher', including 'profile_registry' in options.
00035     """
00036     wrapped = PageTemplateFile( 'siteAddForm', _wwwdir ).__of__( dispatcher )
00037 
00038     base_profiles = []
00039     extension_profiles = []
00040 
00041     for info in profile_registry.listProfileInfo(for_=ISiteRoot):
00042         if info.get('type') == EXTENSION:
00043             extension_profiles.append(info)
00044         else:
00045             base_profiles.append(info)
00046 
00047     return wrapped( base_profiles=tuple(base_profiles),
00048                     extension_profiles =tuple(extension_profiles) )
00049 
00050 def addConfiguredSite(dispatcher, site_id, profile_id, snapshot=True,
00051                       RESPONSE=None, extension_ids=()):
00052     """ Add a CMFSite to 'dispatcher', configured according to 'profile_id'.
00053     """
00054     site = CMFSite( site_id )
00055     dispatcher._setObject( site_id, site )
00056     site = dispatcher._getOb( site_id )
00057     setSite(site)
00058 
00059     site._setObject(_TOOL_ID, SetupTool(_TOOL_ID))
00060     setup_tool = getToolByName(site, _TOOL_ID)
00061 
00062     setup_tool.setBaselineContext('profile-%s' % profile_id)
00063     setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)
00064     for extension_id in extension_ids:
00065         setup_tool.runAllImportStepsFromProfile('profile-%s' % extension_id)
00066 
00067     if snapshot is True:
00068         setup_tool.createSnapshot( 'initial_configuration' )
00069 
00070     if RESPONSE is not None:
00071         RESPONSE.redirect( '%s/%s/manage_main?update_menu=1'
00072                          % (dispatcher.absolute_url(), site_id) )