def _store_size_and_filename_as_metadata(file: File, metadata_appstruct: dict, metadata_sheet: IAssetMetadata, registry: Registry): metadata_appstruct['size'] = file.size metadata_appstruct['filename'] = file.title metadata_sheet.set(metadata_appstruct, omit_readonly=False)
def update_asset_download_children(root, registry): # pragma: no cover """Add asset downloads and update IAssetMetadata sheet.""" from adhocracy_core.sheets.asset import IAssetMetadata from adhocracy_core.sheets.image import IImageMetadata from adhocracy_core.resources.asset import add_metadata from adhocracy_core.resources.image import add_image_size_downloads catalogs = find_service(root, 'catalogs') assets = _search_for_interfaces(catalogs, IAsset) count = len(assets) for index, asset in enumerate(assets): logger.info('Migrating resource {0} of {1}'.format(index + 1, count)) old_downloads = [x for x in asset] for old in old_downloads: del asset[old] try: if IAssetMetadata.providedBy(asset): add_metadata(asset, registry) if IImageMetadata.providedBy(asset): add_image_size_downloads(asset, registry) except AttributeError: logger.warn('Asset {} has no downloads to migrate.'.format(asset))