def purge_deleted_tiles(context): """Purge all annotations of deleted tiles.""" results = api.content.find(object_provides=ICover.__identifier__) logger.info('About to update {0} objects'.format(len(results))) for b in results: obj = b.getObject() obj.purge_deleted_tiles() logger.info('Purged annotations on ' + b.getPath())
def deprecate_resource_registries(setup_tool): """Deprecate resource registries.""" js_tool = api.portal.get_tool('portal_javascripts') for js in JS: 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') for css in 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')
def get_valid_objects(): """Generate a list of objects associated with valid brains.""" results = api.content.find(portal_type='scmos.cover.content') 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
def show_remote_url_field(setup_tool): """Show remote_url field on Basic tiles.""" logger.info(__doc__) results = get_valid_objects() for cover in results: for tile_id in cover.list_tiles(TILE_TYPES): tile = cover.get_tile(tile_id) data_mgr = ITileDataManager(tile) data = data_mgr.get() remote_url = data.get('remote_url') if not remote_url: continue # show information on possible issue path = cover.absolute_url_path() msg = '{0} ("{1}"): remote_url={2}' logger.info(msg.format(path, tile_id, remote_url))
def register_calendar_tile(setup_tool): """Register calendar tile and make it available for inmediate use.""" tile = u'scmos.cover.calendar' record = dict(name='plone.app.tiles') registered_tiles = api.portal.get_registry_record(**record) if tile not in registered_tiles: registered_tiles.append(tile) api.portal.set_registry_record(value=registered_tiles, **record) record = dict(interface=ICoverSettings, name='available_tiles') available_tiles = api.portal.get_registry_record(**record) if tile not in available_tiles: available_tiles.append(tile) api.portal.set_registry_record(value=available_tiles, **record) logger.info('Calendar tile registered and made available')
def fix_image_field_modification_time(context): """Fix image modification time to be float timestamp instead of string.""" covers = context.portal_catalog(object_provides=ICover.__identifier__) logger.info('About to update {0} objects'.format(len(covers))) for cover in covers: obj = cover.getObject() for tile_id in obj.list_tiles(): tile = obj.get_tile(tile_id) dmgr = ITileDataManager(tile) data = dmgr.get() for k, v in data.items(): if not INamedImage.providedBy(v): continue mtime_key = '{0}_mtime'.format(k) data[mtime_key] = float(data[mtime_key]) # need to set changes directly into annotation dmgr.annotations[dmgr.key] = PersistentDict(data) msg = 'Tile {0} at {1} updated' logger.info(msg.format(tile_id, cover.getPath())) logger.info('Done')
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')
def cook_javascript_resources(context): # pragma: no cover """Cook JavaScript resources.""" js_tool = api.portal.get_tool('portal_javascripts') js_tool.cookResources() logger.info('JavaScript resources were cooked')
def register_resource(setup_tool): """Add layout_edit.js to registered resources.""" js_tool = api.portal.get_tool('portal_javascripts') js_tool.registerScript(id=JS, compression='none', authenticated=True) assert JS in js_tool.getResourceIds() # nosec logger.info('Script registered')
def register_calendar_script(setup_tool): """Register script to deal with tile's next/prev events.""" js_tool = api.portal.get_tool('portal_javascripts') js_tool.registerResource('++resource++scmos.cover/js/main.js') logger.info('Calendar script registered')