Пример #1
0
def install_embedder(setup_tool):
    """Install sc.embedder."""
    addon = 'sc.embedder'
    qi = api.portal.get_tool('portal_quickinstaller')
    if not qi.isProductInstalled(addon):
        qi.installProduct(addon)
        logger.info(addon + ' was installed')
Пример #2
0
def install_imagecropping_manager(setup_tool):
    """Install plone.app.imagecropping."""
    addon = 'plone.app.imagecropping'
    qi = api.portal.get_tool('portal_quickinstaller')
    if not qi.isProductInstalled(addon):
        qi.installProduct(addon)
        logger.info(addon + ' was installed')
Пример #3
0
def install_imagecropping_manager(setup_tool):
    """Install plone.app.imagecropping."""
    addon = 'plone.app.imagecropping'
    qi = api.portal.get_tool('portal_quickinstaller')
    if not qi.isProductInstalled(addon):
        qi.installProduct(addon)
        logger.info(addon + ' was installed')
Пример #4
0
def install_embedder(setup_tool):
    """Install sc.embedder."""
    addon = 'sc.embedder'
    qi = api.portal.get_tool('portal_quickinstaller')
    if not qi.isProductInstalled(addon):
        qi.installProduct(addon)
        logger.info(addon + ' was installed')
Пример #5
0
def update_static_resources(setup_tool):
    """Fix resource references after static files reorganization."""
    css_tool = api.portal.get_tool('portal_css')
    _rename_resources(css_tool, RESOURCES_TO_UPDATE)

    logger.info('CSS resources were updated')

    js_tool = api.portal.get_tool('portal_javascripts')
    _rename_resources(js_tool, RESOURCES_TO_UPDATE)
    logger.info('JavaScript resources were updated')
Пример #6
0
def update_static_resources(setup_tool):
    """Fix resource references after static files reorganization."""
    css_tool = api.portal.get_tool('portal_css')
    _rename_resources(css_tool, RESOURCES_TO_UPDATE)

    logger.info('CSS resources were updated')

    js_tool = api.portal.get_tool('portal_javascripts')
    _rename_resources(js_tool, RESOURCES_TO_UPDATE)
    logger.info('JavaScript resources were updated')
Пример #7
0
def make_embedder_searchable(setup_tool):
    """Make Embedder searchable at collective.cover."""
    content_type = 'sc.embedder'
    record = dict(interface=ICoverSettings, name='searchable_content_types')
    searchable_content_types = api.portal.get_registry_record(**record)
    if content_type not in searchable_content_types:
        searchable_content_types.append(content_type)
        api.portal.set_registry_record(value=searchable_content_types, **record)
        logger.info(
            'Embedder was made searchable in collective.cover configlet')
Пример #8
0
def make_embedder_searchable(setup_tool):
    """Make Embedder searchable at collective.cover."""
    content_type = 'sc.embedder'
    record = dict(interface=ICoverSettings, name='searchable_content_types')
    searchable_content_types = api.portal.get_registry_record(**record)
    if content_type not in searchable_content_types:
        searchable_content_types.append(content_type)
        api.portal.set_registry_record(value=searchable_content_types,
                                       **record)
        logger.info(
            'Embedder was made searchable in collective.cover configlet')
Пример #9
0
def deprecate_resource_registries(setup_tool):
    """Deprecate resource registries."""
    js_tool = api.portal.get_tool('portal_javascripts')
    if JS in js_tool.getResourceIds():
        js_tool.unregisterResource(id=JS)
    assert JS not in js_tool.getResourceIds()  # nosec

    css_tool = api.portal.get_tool('portal_css')
    if CSS in css_tool.getResourceIds():
        css_tool.unregisterResource(id=CSS)
    assert CSS not in css_tool.getResourceIds()  # nosec

    logger.info('Static resources successfully removed from registries')
Пример #10
0
def get_valid_objects(**kw):
    """Generate a list of objects associated with valid brains."""
    results = api.content.find(**kw)
    logger.info('Found {0} objects in the catalog'.format(len(results)))
    for b in results:
        try:
            obj = b.getObject()
        except (AttributeError, KeyError):
            obj = None

        if obj is None:  # warn on broken entries in the catalog
            msg = 'Invalid object reference in the catalog: {0}'
            logger.warn(msg.format(b.getPath()))
            continue

        yield obj
Пример #11
0
def get_valid_objects(**kw):
    """Generate a list of objects associated with valid brains."""
    results = api.content.find(**kw)
    logger.info('Found {0} objects in the catalog'.format(len(results)))
    for b in results:
        try:
            obj = b.getObject()
        except (AttributeError, KeyError):
            obj = None

        if obj is None:  # warn on broken entries in the catalog
            msg = 'Invalid object reference in the catalog: {0}'
            logger.warn(msg.format(b.getPath()))
            continue

        yield obj
Пример #12
0
def migrate_tiles_data_removed(setup_tool):
    """The "List" tile in brasil.gov.tiles has been removed to use
       collective.cover, it is necessary to migrate the data.

       Tiles affected: audiogallery, videogallery e collective.cover.list
    """

    from brasil.gov.tiles.upgrades import replace_attribute_data

    TILES = [
        u'audiogallery',
        u'videogallery',
        u'collective.cover.list',
    ]

    for obj in get_valid_objects(portal_type='collective.cover.content'):
        for tile in TILES:
            replace_attribute(obj, tile, 'header', 'tile_title')
            replace_attribute_data(obj, tile, 'uuids')
    logger.info('Done')
Пример #13
0
def migrate_tiles_data_removed(setup_tool):
    """The "List" tile in brasil.gov.tiles has been removed to use
       collective.cover, it is necessary to migrate the data.

       Tiles affected: audiogallery, videogallery e collective.cover.list
    """

    from brasil.gov.tiles.upgrades import replace_attribute_data

    TILES = [
        u'audiogallery',
        u'videogallery',
        u'collective.cover.list',
    ]

    for obj in get_valid_objects(portal_type='collective.cover.content'):
        for tile in TILES:
            replace_attribute(obj, tile, 'header', 'tile_title')
            replace_attribute_data(obj, tile, 'uuids')
    logger.info('Done')
Пример #14
0
def migrate_deprecated_tiles(setup_tool):
    """Migrate deprecated tiles.

    - tiles with a substitute will be migrated
    - tiles with no substitute will be removed
    """
    from brasil.gov.tiles.upgrades import remove_tile
    from brasil.gov.tiles.upgrades import replace_tile

    logger.info('Migrating IDG tiles on collective.cover objects')
    logger.warn('All tiles with no substitute will be removed from layouts')
    results = get_valid_objects(portal_type='collective.cover.content')
    for obj in results:
        try:
            layout = json.loads(obj.cover_layout)
        except TypeError:
            continue  # empty layout?

        for old, new in DEPRECATED_TILES:
            if new is None:
                layout = remove_tile(layout, old)
            elif old != new:
                layout = replace_tile(layout, old, new)
            obj.cover_layout = json.dumps(layout)

    logger.info('Migrating attributes on tiles')
    for obj in results:
        replace_attribute(obj, new, 'image_description', 'alt_text')

    logger.info('Done')
Пример #15
0
def migrate_deprecated_tiles(setup_tool):
    """Migrate deprecated tiles.

    - tiles with a substitute will be migrated
    - tiles with no substitute will be removed
    """
    from brasil.gov.tiles.upgrades import remove_tile
    from brasil.gov.tiles.upgrades import replace_tile

    logger.info('Migrating IDG tiles on collective.cover objects')
    logger.warn('All tiles with no substitute will be removed from layouts')
    results = get_valid_objects(portal_type='collective.cover.content')
    for obj in results:
        try:
            layout = json.loads(obj.cover_layout)
        except TypeError:
            continue  # empty layout?

        for old, new in DEPRECATED_TILES:
            if new is None:
                layout = remove_tile(layout, old)
            elif old != new:
                layout = replace_tile(layout, old, new)
            obj.cover_layout = json.dumps(layout)

    logger.info('Migrating attributes on tiles')
    for obj in results:
        replace_attribute(obj, new, 'image_description', 'alt_text')

    logger.info('Done')
Пример #16
0
def add_tile(tile):
    """Register a tile and make it available."""
    from brasil.gov.tiles.utils import enable_tile
    enable_tile(tile)
    logger.info('{0} tile added'.format(tile))
Пример #17
0
def cook_javascript_resources(context):  # pragma: no cover
    """Cook JavaScripts resources."""
    js_tool = api.portal.get_tool('portal_javascripts')
    js_tool.cookResources()
    logger.info('JavaScripts resources were cooked')
Пример #18
0
def cook_javascript_resources(context):  # pragma: no cover
    """Cook JavaScripts resources."""
    js_tool = api.portal.get_tool('portal_javascripts')
    js_tool.cookResources()
    logger.info('JavaScripts resources were cooked')
Пример #19
0
def add_tile(tile):
    """Register a tile and make it available."""
    from brasil.gov.tiles.utils import enable_tile
    enable_tile(tile)
    logger.info('{0} tile added'.format(tile))
Пример #20
0
def cook_css_resources(context):  # pragma: no cover
    """Cook CSS resources."""
    css_tool = api.portal.get_tool('portal_css')
    css_tool.cookResources()
    logger.info('CSS resources were cooked')
Пример #21
0
def cook_css_resources(context):  # pragma: no cover
    """Cook CSS resources."""
    css_tool = api.portal.get_tool('portal_css')
    css_tool.cookResources()
    logger.info('CSS resources were cooked')