Exemple #1
0
def add_metadata(context: IAsset, registry: Registry, **kwargs):
    """Store asset file metadata and add `raw` download to `context`."""
    file = get_sheet_field(context, IAssetData, 'data', registry=registry)
    meta_isheet = get_matching_isheet(context, IAssetMetadata)
    meta_sheet = get_sheet(context, meta_isheet, registry=registry)
    meta_appstruct = {
        'size': file.size,
        'filename': file.title,
    }
    meta_sheet.set(meta_appstruct, omit_readonly=False)
Exemple #2
0
def add_metadata(context: IAsset, registry: Registry, **kwargs):
    """Store asset file metadata and add `raw` download to `context`."""
    file = registry.content.get_sheet_field(context, IAssetData, 'data')
    meta_isheet = get_matching_isheet(context, IAssetMetadata)
    meta_sheet = registry.content.get_sheet(context, meta_isheet)
    meta_appstruct = {
        'size': file.size,
        'filename': file.title,
        'mime_type': file.mimetype,
    }
    meta_sheet.set(meta_appstruct, omit_readonly=False)
Exemple #3
0
def add_image_size_downloads(context: IImage, registry: Registry, **kwargs):
    """Add download for every image size of `context`."""
    isheet = get_matching_isheet(context,
                                 adhocracy_core.sheets.image.IImageMetadata)
    sheet = registry.content.get_sheet(context, isheet)
    size_fields = (f for f in sheet.schema if hasattr(f, 'dimensions'))
    appstruct = {}
    for field in size_fields:
        download = registry.content.create(IImageDownload.__identifier__,
                                           parent=context)
        download.dimensions = field.dimensions
        appstruct[field.name] = download
    sheet.set(appstruct, omit_readonly=False)
Exemple #4
0
def add_image_size_downloads(context: IImage, registry: Registry, **kwargs):
    """Add download for every image size of `context`."""
    isheet = get_matching_isheet(context,
                                 adhocracy_core.sheets.image.IImageMetadata)
    sheet = registry.content.get_sheet(context, isheet)
    size_fields = (f for f in sheet.schema if hasattr(f, 'dimensions'))
    appstruct = {}
    for field in size_fields:
        download = registry.content.create(IImageDownload.__identifier__,
                                           parent=context)
        download.dimensions = field.dimensions
        appstruct[field.name] = download
    sheet.set(appstruct, omit_readonly=False)
Exemple #5
0
def validate_and_complete_asset(context: IAsset,
                                registry: Registry,
                                options: dict={}):
    """Complete the initialization of an asset and ensure that it's valid."""
    data_sheet = get_sheet(context, IAssetData, registry=registry)
    data_appstruct = data_sheet.get()
    metadata_isheet = get_matching_isheet(context, IAssetMetadata)
    metadata_sheet = get_sheet(context, metadata_isheet, registry=registry)
    metadata_appstruct = metadata_sheet.get()
    file = data_appstruct['data']
    if not file:
        return  # to facilitate testing
    _validate_mime_type(file, metadata_appstruct, metadata_sheet)
    _store_size_and_filename_as_metadata(file,
                                         metadata_appstruct,
                                         metadata_sheet,
                                         registry=registry)
    _add_downloads_as_children(context, metadata_sheet, registry)
Exemple #6
0
def validate_and_complete_asset(context: IAsset,
                                registry: Registry,
                                options: dict = {}):
    """Complete the initialization of an asset and ensure that it's valid."""
    data_sheet = get_sheet(context, IAssetData, registry=registry)
    data_appstruct = data_sheet.get()
    metadata_isheet = get_matching_isheet(context, IAssetMetadata)
    metadata_sheet = get_sheet(context, metadata_isheet, registry=registry)
    metadata_appstruct = metadata_sheet.get()
    file = data_appstruct['data']
    if not file:
        return  # to facilitate testing
    _validate_mime_type(file, metadata_appstruct, metadata_sheet)
    _store_size_and_filename_as_metadata(file,
                                         metadata_appstruct,
                                         metadata_sheet,
                                         registry=registry)
    _add_downloads_as_children(context, metadata_sheet, registry)
 def call_fut(self, context, isheet):
     from adhocracy_core.utils import get_matching_isheet
     return get_matching_isheet(context, isheet)
Exemple #8
0
 def call_fut(self, context, isheet):
     from adhocracy_core.utils import get_matching_isheet
     return get_matching_isheet(context, isheet)