Exemple #1
0
def addPloneSite(context,
                 site_id,
                 title='Plone site',
                 description='',
                 create_userfolder=True,
                 email_from_address='',
                 email_from_name='',
                 validate_email=True,
                 profile_id=_DEFAULT_PROFILE,
                 snapshot=False,
                 extension_ids=(),
                 base_contenttypes_profile=_ATCONTENTTYPES_PROFILE,
                 setup_content=True,
                 default_language='en'):
    """Add a PloneSite to the context."""
    context._setObject(site_id, PloneSite(site_id))
    site = context._getOb(site_id)
    site.setLanguage(default_language)

    site[_TOOL_ID] = SetupTool(_TOOL_ID)
    setup_tool = site[_TOOL_ID]

    notify(SiteManagerCreatedEvent(site))
    setSite(site)

    setup_tool.setBaselineContext('profile-%s' % profile_id)
    setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)
    if base_contenttypes_profile is not None \
       and base_contenttypes_profile in _CONTENTTYPES_PROFILES:
        profile = 'profile-%s' % base_contenttypes_profile
        setup_tool.runAllImportStepsFromProfile(profile)
        # Only set up content if a base contenttypes profile has been provided.
        if setup_content:
            if base_contenttypes_profile == _ATCONTENTTYPES_PROFILE:
                content_profile = _AT_CONTENT_PROFILE
            else:
                content_profile = _DEX_CONTENT_PROFILE
            setup_tool.runAllImportStepsFromProfile('profile-%s' %
                                                    content_profile)

    props = dict(
        title=title,
        description=description,
        email_from_address=email_from_address,
        email_from_name=email_from_name,
        validate_email=validate_email,
    )
    # Do this before applying extension profiles, so the settings from a
    # properties.xml file are applied and not overwritten by this
    site.manage_changeProperties(**props)

    for extension_id in extension_ids:
        setup_tool.runAllImportStepsFromProfile('profile-%s' % extension_id)

    if snapshot is True:
        setup_tool.createSnapshot('initial_configuration')

    return site
def addPloneSite(context,
                 site_id,
                 title='Plone site',
                 description='',
                 profile_id=_DEFAULT_PROFILE,
                 content_profile_id=_CONTENT_PROFILE,
                 snapshot=False,
                 extension_ids=(),
                 setup_content=True,
                 default_language='en',
                 portal_timezone='UTC'):
    """Add a PloneSite to the context."""
    context._setObject(site_id, PloneSite(site_id))
    site = context._getOb(site_id)
    site.setLanguage(default_language)
    # Set the accepted language for the rest of the request.  This makes sure
    # the front-page text gets the correct translation also when your browser
    # prefers non-English and you choose English as language for the Plone
    # Site.
    request = context.REQUEST
    request['HTTP_ACCEPT_LANGUAGE'] = default_language

    site[_TOOL_ID] = SetupTool(_TOOL_ID)
    setup_tool = site[_TOOL_ID]

    notify(SiteManagerCreatedEvent(site))
    setSite(site)

    setup_tool.setBaselineContext('profile-%s' % profile_id)
    setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)

    reg = queryUtility(IRegistry, context=site)
    reg['plone.portal_timezone'] = portal_timezone
    reg['plone.available_timezones'] = [portal_timezone]
    reg['plone.default_language'] = default_language
    reg['plone.available_languages'] = [default_language]

    if setup_content:
        setup_tool.runAllImportStepsFromProfile('profile-%s' %
                                                content_profile_id)

    props = dict(
        title=title,
        description=description,
    )
    # Do this before applying extension profiles, so the settings from a
    # properties.xml file are applied and not overwritten by this
    site.manage_changeProperties(**props)

    for extension_id in extension_ids:
        setup_tool.runAllImportStepsFromProfile('profile-%s' % extension_id)

    if snapshot is True:
        setup_tool.createSnapshot('initial_configuration')

    return site
def addPloneSite(context,
                 site_id,
                 title='Plone site',
                 description='',
                 profile_id=_DEFAULT_PROFILE,
                 content_profile_id=_CONTENT_PROFILE,
                 snapshot=False,
                 extension_ids=(),
                 setup_content=True,
                 default_language='en',
                 portal_timezone='UTC'):
    """Add a PloneSite to the context."""
    context._setObject(site_id, PloneSite(site_id))
    site = context._getOb(site_id)
    site.setLanguage(default_language)

    site[_TOOL_ID] = SetupTool(_TOOL_ID)
    setup_tool = site[_TOOL_ID]

    notify(SiteManagerCreatedEvent(site))
    setSite(site)

    setup_tool.setBaselineContext('profile-%s' % profile_id)
    setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)

    reg = queryUtility(IRegistry, context=site)
    reg['plone.portal_timezone'] = portal_timezone
    reg['plone.available_timezones'] = [portal_timezone]
    reg['plone.default_language'] = default_language
    reg['plone.available_languages'] = [default_language]

    if setup_content:
        setup_tool.runAllImportStepsFromProfile('profile-%s' %
                                                content_profile_id)

    props = dict(
        title=title,
        description=description,
    )
    # Do this before applying extension profiles, so the settings from a
    # properties.xml file are applied and not overwritten by this
    site.manage_changeProperties(**props)

    for extension_id in extension_ids:
        setup_tool.runAllImportStepsFromProfile('profile-%s' % extension_id)

    if snapshot is True:
        setup_tool.createSnapshot('initial_configuration')

    return site
def addPloneSite(context,
                 site_id,
                 title='Plone site',
                 description='',
                 profile_id=_DEFAULT_PROFILE,
                 content_profile_id=_CONTENT_PROFILE,
                 snapshot=False,
                 extension_ids=(),
                 setup_content=True,
                 default_language='en',
                 portal_timezone='UTC'):
    """Add a PloneSite to the context."""
    context._setObject(site_id, PloneSite(site_id))
    site = context._getOb(site_id)
    site.setLanguage(default_language)
    # Set the accepted language for the rest of the request.  This makes sure
    # the front-page text gets the correct translation also when your browser
    # prefers non-English and you choose English as language for the Plone
    # Site.
    request = context.REQUEST
    request['HTTP_ACCEPT_LANGUAGE'] = default_language

    site[_TOOL_ID] = SetupTool(_TOOL_ID)
    setup_tool = site[_TOOL_ID]

    notify(SiteManagerCreatedEvent(site))
    setSite(site)

    setup_tool.setBaselineContext('profile-%s' % profile_id)
    setup_tool.runAllImportStepsFromProfile('profile-%s' % profile_id)

    reg = queryUtility(IRegistry, context=site)
    reg['plone.portal_timezone'] = portal_timezone
    reg['plone.available_timezones'] = [portal_timezone]
    reg['plone.default_language'] = default_language
    reg['plone.available_languages'] = [default_language]

    if setup_content:
        setup_tool.runAllImportStepsFromProfile('profile-%s' %
                                                content_profile_id)

    props = dict(
        title=title,
        description=description,
    )
    # Do this before applying extension profiles, so the settings from a
    # properties.xml file are applied and not overwritten by this
    site.manage_changeProperties(**props)

    for extension_id in extension_ids:
        try:
            setup_tool.runAllImportStepsFromProfile('profile-%s' %
                                                    extension_id)
        except Exception as msg:
            IStatusMessage(request).add(_(
                'Could not install ${profile_id}: ${error_msg}! '
                'Please try to install it manually using the "Addons" '
                'controlpanel and report any issues to the '
                'addon maintainers.',
                mapping={
                    'profile_id': extension_id,
                    'error_msg': msg.args,
                }),
                                        type='error')
            logger.exception(
                'Error while installing addon {}. '
                'See traceback below for details.'.format(extension_id))

    if snapshot is True:
        setup_tool.createSnapshot('initial_configuration')

    return site