Exemple #1
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)


image_meta = asset_meta._replace(
    content_name='Image',
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(adhocracy_core.sheets.image.IImageMetadata, ),
    use_autonaming=False,
    use_autonaming_random=True,
)._add(after_creation=(add_image_size_downloads, ))


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)
    add_resource_type_to_registry(image_download_meta, config)
Exemple #2
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)


image_meta = asset_meta._replace(
    content_name='Image',
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(adhocracy_core.sheets.image.IImageMetadata,),
    use_autonaming=False,
    use_autonaming_random=True,
)._add(after_creation=(add_image_size_downloads,))


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)
    add_resource_type_to_registry(image_download_meta, config)
    item_type=IOrganizationInfoVersion,
    permission_create='edit_mercator_proposal',
    autonaming_prefix='info_',
)._add(after_creation=(add_commentsservice,))


class IIntroImage(IAsset):

    """Image attached to the introduction of a proposal."""


intro_image_meta = asset_meta._replace(
    content_name='IIntroImage',
    iresource=IIntroImage,
    is_implicit_addable=True,
    # replace IAssetMetadata sheet by IIntroImageMetadata
    basic_sheets=tuple(
        set(asset_meta.basic_sheets) - {IAssetMetadata, }
        | {adhocracy_mercator.sheets.mercator.IIntroImageMetadata, }),
)


class IIntroductionVersion(IItemVersion):

    """One of the mercator commentable subresources."""


introduction_version_meta = itemversion_meta._replace(
    content_name='IntroductionVersion',
    iresource=IIntroductionVersion,
    extended_sheets=(
"""image resource type."""

from adhocracy_core.resources import add_resource_type_to_registry
from adhocracy_core.resources.asset import asset_meta
from adhocracy_core.resources.asset import IAsset
from adhocracy_core.sheets.image import IImageMetadata


class IImage(IAsset):

    """An image asset, provided as example."""


image_meta = asset_meta._replace(
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(IImageMetadata,),
)


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)
Exemple #5
0
class IImage(IAsset):
    """An image asset."""


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 = get_sheet(context, isheet, registry=registry)
    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)


image_meta = asset_meta._replace(
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(adhocracy_core.sheets.image.IImageMetadata, ),
)._add(after_creation=(add_image_size_downloads, ))


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)
    add_resource_type_to_registry(image_download_meta, config)
Exemple #6
0
class IImage(IAsset):
    """An image asset."""


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 = get_sheet(context, isheet, registry=registry)
    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)


image_meta = asset_meta._replace(
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(adhocracy_core.sheets.image.IImageMetadata,),
)._add(after_creation=(add_image_size_downloads,))


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)
    add_resource_type_to_registry(image_download_meta, config)
Exemple #7
0
    permission_create='edit_mercator_proposal',
    autonaming_prefix='info_',
)._add(after_creation=(add_commentsservice, ))


class IIntroImage(IAsset):
    """Image attached to the introduction of a proposal."""


intro_image_meta = asset_meta._replace(
    content_name='IIntroImage',
    iresource=IIntroImage,
    is_implicit_addable=True,
    # replace IAssetMetadata sheet by IIntroImageMetadata
    basic_sheets=tuple(
        set(asset_meta.basic_sheets) - {
            IAssetMetadata,
        }
        | {
            adhocracy_mercator.sheets.mercator.IIntroImageMetadata,
        }),
)


class IIntroductionVersion(IItemVersion):
    """One of the mercator commentable subresources."""


introduction_version_meta = itemversion_meta._replace(
    content_name='IntroductionVersion',
    iresource=IIntroductionVersion,
"""image resource type."""

from adhocracy_core.resources import add_resource_type_to_registry
from adhocracy_core.resources.asset import asset_meta
from adhocracy_core.resources.asset import IAsset
from adhocracy_core.sheets.image import IImageMetadata


class IImage(IAsset):
    """An image asset, provided as example."""


image_meta = asset_meta._replace(
    iresource=IImage,
    is_implicit_addable=True,
    extended_sheets=(IImageMetadata, ),
)


def includeme(config):
    """Add resource type to registry."""
    add_resource_type_to_registry(image_meta, config)