overrides={ 'document_id': { 'missing': None }, 'version': { 'missing': None }, 'locales': { 'children': [schema_document_locale] }, 'geometry': geometry_schema_overrides }) schema_update_topo_map = get_update_schema(schema_topo_map) schema_listing_topo_map = restrict_schema(schema_topo_map, fields_topo_map.get('listing')) # TODO cache on document_id and lang (empty the cache if the document geometry # has changed or any maps was updated/created) def get_maps(document, lang): """Load and return maps that intersect with the document geometry. """ if document.geometry is None: return [] document_geom = select([DocumentGeometry.geom]). \ where(DocumentGeometry.document_id == document.document_id) document_geom_detail = select([DocumentGeometry.geom_detail]). \ where(DocumentGeometry.document_id == document.document_id) topo_maps = DBSession. \
ForeignKey(schema + '.documents_archives.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': MAP_TYPE, 'inherit_condition': ArchiveDocument.id == id } __table_args__ = Base.__table_args__ schema_topo_map = SQLAlchemySchemaNode( TopoMap, # whitelisted attributes includes=schema_attributes + attributes, overrides={ 'document_id': { 'missing': None }, 'version': { 'missing': None }, 'locales': { 'children': [schema_document_locale] }, 'geometry': geometry_schema_overrides }) schema_update_topo_map = get_update_schema(schema_topo_map) schema_listing_topo_map = restrict_schema( schema_topo_map, fields_topo_map.get('listing'))
from c2corg_api.models.topo_map import (TopoMap, schema_topo_map, schema_update_topo_map, MAP_TYPE) from c2corg_api.models.topo_map_association import update_map from c2corg_api.views.document_info import DocumentInfoRest from c2corg_api.views.document_schemas import topo_map_documents_config from c2corg_common.fields_topo_map import fields_topo_map from cornice.resource import resource, view from cornice.validators import colander_body_validator 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_lang validate_map_create = make_validator_create(fields_topo_map.get('required')) validate_map_update = make_validator_update(fields_topo_map.get('required')) @resource(collection_path='/maps', path='/maps/{id}', cors_policy=cors_policy) class TopoMapRest(DocumentRest): @view(validators=[validate_pagination, validate_preferred_lang_param]) def collection_get(self): return self._collection_get(MAP_TYPE, topo_map_documents_config) @view(validators=[validate_id, validate_lang_param]) def get(self): return self._get(TopoMap, schema_topo_map) @restricted_json_view( schema=schema_topo_map,
from c2corg_api.views.document_schemas import topo_map_documents_config from c2corg_common.fields_topo_map import fields_topo_map from cornice.resource import resource, view from cornice.validators import colander_body_validator 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_lang, ) validate_map_create = make_validator_create(fields_topo_map.get("required")) validate_map_update = make_validator_update(fields_topo_map.get("required")) @resource(collection_path="/maps", path="/maps/{id}", cors_policy=cors_policy) class TopoMapRest(DocumentRest): @view(validators=[validate_pagination, validate_preferred_lang_param]) def collection_get(self): return self._collection_get(MAP_TYPE, topo_map_documents_config) @view(validators=[validate_id, validate_lang_param]) def get(self): return self._get(TopoMap, schema_topo_map) @restricted_json_view( schema=schema_topo_map, validators=[colander_body_validator, validate_map_create], permission="moderator"