예제 #1
0
파일: image.py 프로젝트: sriks123/v6_api
def validate_list_image_create(request, **kwargs):
    if not request.validated.get('images'):
        return

    for image in request.validated['images']:
        validate_document(image, request, fields_image.get('required'),
                          updating=False)
        check_filename_unique(image, request, updating=False)
예제 #2
0
파일: image.py 프로젝트: c2corg/v6_api
        'document_id': {
            'missing': None
        },
        'version': {
            'missing': None
        },
        'locales': {
            'children': [schema_image_locale]
        },
        'geometry': geometry_schema_overrides
    })

schema_create_image = get_create_schema(schema_image)
schema_update_image = get_update_schema(schema_image)
schema_listing_image = restrict_schema(
    schema_image, fields_image.get('listing'))
schema_association_image = restrict_schema(schema_image, [
    'filename', 'locales.title', 'geometry.geom'
])


class SchemaImageList(MappingSchema):
    images = SchemaNode(
        Sequence(), schema_create_image, missing=None)
schema_create_image_list = SchemaImageList()


def is_personal(image_id):
    image_type = DBSession.query(Image.image_type). \
        select_from(Image.__table__). \
        filter(Image.document_id == image_id). \
예제 #3
0
파일: image.py 프로젝트: sriks123/v6_api
        'document_id': {
            'missing': None
        },
        'version': {
            'missing': None
        },
        'locales': {
            'children': [schema_image_locale]
        },
        'geometry': get_geometry_schema_overrides(['POINT'])
    })

schema_create_image = get_create_schema(schema_image)
schema_update_image = get_update_schema(schema_image)
schema_listing_image = restrict_schema(
    schema_image, fields_image.get('listing'))
schema_association_image = restrict_schema(schema_image, [
    'filename', 'locales.title', 'geometry.geom'
])


class SchemaImageList(MappingSchema):
    images = SchemaNode(
        Sequence(), schema_create_image, missing=None)
schema_create_image_list = SchemaImageList()


def is_personal(image_id):
    image_type = DBSession.query(Image.image_type). \
        select_from(Image.__table__). \
        filter(Image.document_id == image_id). \
예제 #4
0
        'polymorphic_identity': IMAGE_TYPE,
        'inherit_condition': ArchiveDocument.id == id
    }

    __table_args__ = Base.__table_args__


schema_image = SQLAlchemySchemaNode(
    Image,
    # whitelisted attributes
    includes=schema_attributes + attributes,
    overrides={
        'document_id': {
            'missing': None
        },
        'version': {
            'missing': None
        },
        'locales': {
            'children': [schema_document_locale]
        },
        'geometry': geometry_schema_overrides
    })

schema_create_image = get_create_schema(schema_image)
schema_update_image = get_update_schema(schema_image)
schema_listing_image = restrict_schema(schema_image,
                                       fields_image.get('listing'))
schema_association_image = restrict_schema(schema_image,
                                           ['filename', 'locales.title'])
예제 #5
0
파일: image.py 프로젝트: millerf/v6_api
    if updating:

        def f(request, **kwargs):
            image = request.validated
            check_filename_unique(image, request, updating=True)
    else:

        def f(request, **kwargs):
            image = request.validated
            check_filename_unique(image, request, updating=False)

    return f


base_validate_image_create = make_validator_create(
    fields_image.get('required'))
base_validate_image_update = make_validator_update(
    fields_image.get('required'))
validate_filename_create = make_validator_filename_unique(updating=False)
validate_filename_update = make_validator_filename_unique(updating=True)


def validate_image_create(request, **kwargs):
    base_validate_image_create(request, **kwargs)
    validate_filename_create(request, **kwargs)


def validate_image_update(request, **kwargs):
    base_validate_image_update(request, **kwargs)
    validate_filename_update(request, **kwargs)
예제 #6
0
파일: image.py 프로젝트: c2corg/v6_api
def validate_list_image_create(request, **kwargs):
    for image in request.validated['images']:
        validate_document(image, request, fields_image.get('required'),
                          updating=False)
        check_filename_unique(image, request, updating=False)
예제 #7
0
파일: image.py 프로젝트: c2corg/v6_api

def make_validator_filename_unique(updating):
    if updating:
        def f(request, **kwargs):
            image = request.validated
            check_filename_unique(image, request, updating=True)
    else:
        def f(request, **kwargs):
            image = request.validated
            check_filename_unique(image, request, updating=False)
    return f


base_validate_image_create = make_validator_create(
        fields_image.get('required'))
base_validate_image_update = make_validator_update(
        fields_image.get('required'))
validate_filename_create = make_validator_filename_unique(updating=False)
validate_filename_update = make_validator_filename_unique(updating=True)


def validate_image_create(request, **kwargs):
    base_validate_image_create(request, **kwargs)
    validate_filename_create(request, **kwargs)


def validate_image_update(request, **kwargs):
    base_validate_image_update(request, **kwargs)
    validate_filename_update(request, **kwargs)
예제 #8
0
from c2corg_api.models.document_history import has_been_created_by
from c2corg_api.models.image import Image, schema_image, schema_update_image, \
    schema_listing_image, IMAGE_TYPE, schema_create_image
from c2corg_common.fields_image import fields_image
from cornice.resource import resource, view

from c2corg_api.views.document import DocumentRest, make_validator_create, \
    make_validator_update
from c2corg_api.views import cors_policy, restricted_json_view
from c2corg_api.views.validation import validate_id, validate_pagination, \
    validate_lang_param, validate_preferred_lang_param, \
    validate_associations

from pyramid.httpexceptions import HTTPForbidden, HTTPNotFound, HTTPBadRequest

validate_image_create = make_validator_create(fields_image.get('required'))
validate_image_update = make_validator_update(fields_image.get('required'))
validate_associations_create = functools.partial(
    validate_associations, IMAGE_TYPE, True)
validate_associations_update = functools.partial(
    validate_associations, IMAGE_TYPE, False)


@resource(collection_path='/images', path='/images/{id}',
          cors_policy=cors_policy)
class ImageRest(DocumentRest):

    @view(validators=[validate_pagination, validate_preferred_lang_param])
    def collection_get(self):
        return self._collection_get(Image, schema_listing_image, IMAGE_TYPE)