Exemplo n.º 1
0
from cornice.resource import resource, view
from cornice.validators import colander_body_validator
from c2corg_api.views import set_creator as set_creator_on_documents

from c2corg_api.views.document_schemas import xreport_documents_config
from c2corg_api.views.document import DocumentRest, make_validator_create, \
    make_validator_update
from c2corg_api.views import cors_policy, restricted_json_view, \
    set_private_cache_header
from c2corg_api.views.validation import validate_id, validate_pagination, \
    validate_lang_param, validate_preferred_lang_param, \
    validate_associations, validate_lang, validate_version_id

from pyramid.httpexceptions import HTTPForbidden

validate_xreport_create = make_validator_create(fields_xreport.get('required'))
validate_xreport_update = make_validator_update(fields_xreport.get('required'))
validate_associations_create = functools.partial(
    validate_associations, XREPORT_TYPE, True)
validate_associations_update = functools.partial(
    validate_associations, XREPORT_TYPE, False)


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

    @view(validators=[validate_pagination, validate_preferred_lang_param])
    def collection_get(self):
        return self._collection_get(XREPORT_TYPE, xreport_documents_config)
Exemplo n.º 2
0
from cornice.validators import colander_body_validator
from c2corg_api.views import set_creator as set_creator_on_documents

from c2corg_api.views.document_schemas import xreport_documents_config
from c2corg_api.views.document import DocumentRest, make_validator_create, \
    make_validator_update
from c2corg_api.views import cors_policy, restricted_json_view, \
    set_private_cache_header
from c2corg_api.views.validation import validate_id, validate_pagination, \
    validate_lang_param, validate_preferred_lang_param, \
    validate_associations, validate_lang, validate_version_id, \
    is_associated_user

from pyramid.httpexceptions import HTTPForbidden

validate_xreport_create = make_validator_create(fields_xreport.get('required'))
validate_xreport_update = make_validator_update(fields_xreport.get('required'))
validate_associations_create = functools.partial(
    validate_associations, XREPORT_TYPE, True)
validate_associations_update = functools.partial(
    validate_associations, XREPORT_TYPE, False)


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

    @view(validators=[validate_pagination, validate_preferred_lang_param])
    def collection_get(self):
        return self._collection_get(XREPORT_TYPE, xreport_documents_config)
Exemplo n.º 3
0
            'missing': None
        },
        'locales': {
            'children': [schema_xreport_locale],
        },
        'activities': {
            'validator': colander.Length(min=1)
        },
        'geometry': geometry_schema_overrides
    })

# schema that hides personal information of a xreport
schema_xreport_without_personal = SQLAlchemySchemaNode(
    Xreport,
    # whitelisted attributes
    includes=schema_attributes + attributes_without_personal,
    overrides={
        'locales': {
            'children': [schema_xreport_locale],
        },
        'geometry': geometry_schema_overrides
    })


schema_create_xreport = get_create_schema(schema_xreport)
schema_update_xreport = get_update_schema(schema_xreport)
schema_listing_xreport = restrict_schema(
    schema_xreport,
    fields_xreport.get('listing')
)
Exemplo n.º 4
0
    includes=schema_attributes + attributes,
    overrides={
        'document_id': {
            'missing': None
        },
        'version': {
            'missing': None
        },
        'locales': {
            'children': [schema_xreport_locale],
        },
        'geometry': get_geometry_schema_overrides(['POINT'])
    })

# schema that hides personal information of a xreport
schema_xreport_without_personal = SQLAlchemySchemaNode(
    Xreport,
    # whitelisted attributes
    includes=schema_attributes + attributes_without_personal,
    overrides={
        'locales': {
            'children': [schema_xreport_locale],
        },
        'geometry': get_geometry_schema_overrides(['POINT'])
    })

schema_create_xreport = get_create_schema(schema_xreport)
schema_update_xreport = get_update_schema(schema_xreport)
schema_listing_xreport = restrict_schema(schema_xreport,
                                         fields_xreport.get('listing'))