From 64754a34bb342903fd2bfb80db389b20b273aff7 Mon Sep 17 00:00:00 2001 From: Anna Trzcinska Date: Fri, 15 Nov 2019 14:16:04 +0100 Subject: [PATCH] schemas: add SimplifiedSchemaSerializer Signed-off-by: Anna Trzcinska --- cap/modules/records/utils.py | 6 +++--- cap/modules/schemas/serializers.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cap/modules/records/utils.py b/cap/modules/records/utils.py index 512386ef4a..548cd16e24 100644 --- a/cap/modules/records/utils.py +++ b/cap/modules/records/utils.py @@ -92,9 +92,9 @@ def _get_json_type(): schema_url, _get_json_type())).values(RecordMetadata.id)) filtered_by_pid_type = (x[0] for x in PersistentIdentifier.query.filter( - PersistentIdentifier.object_type == 'rec', - PersistentIdentifier.pid_type == pid_type, PersistentIdentifier.status - == PIDStatus.REGISTERED, PersistentIdentifier.object_uuid.in_( + PersistentIdentifier.status == PIDStatus.REGISTERED, + PersistentIdentifier.object_type == 'rec', PersistentIdentifier. + pid_type == pid_type, PersistentIdentifier.object_uuid.in_( ids)).values(PersistentIdentifier.object_uuid)) print('{} records will be reindexed...'.format(schema_url)) diff --git a/cap/modules/schemas/serializers.py b/cap/modules/schemas/serializers.py index 36f0e7c652..7871d98c23 100644 --- a/cap/modules/schemas/serializers.py +++ b/cap/modules/schemas/serializers.py @@ -25,10 +25,10 @@ import copy from flask import url_for -from invenio_jsonschemas.proxies import current_jsonschemas -from marshmallow import Schema, ValidationError, fields, pre_load, validate from cap.utils import url_to_api_url +from invenio_jsonschemas.proxies import current_jsonschemas +from marshmallow import Schema, ValidationError, fields, pre_load, validate from .validators import JSONSchemaValidator @@ -102,6 +102,15 @@ def filter_out_fields_that_cannot_be_updated(self, data, **kwargs): return data +class SimplifiedSchemaSerializer(Schema): + """Simplified serializer for schema.""" + + name = fields.Str(dump_only=True, required=True) + version = fields.Str(dump_only=True, required=True, + validate=validate.Regexp(regex=r"(\d+).(\d+).(\d+)")) + fullname = fields.Str(dump_only=True) + + class ResolvedSchemaSerializer(SchemaSerializer): """Schema serializer with resolved jsonschemas.""" @@ -125,5 +134,6 @@ def get_resolved_record_schema(self, obj): schema_serializer = SchemaSerializer() +simplified_schema_serializer = SimplifiedSchemaSerializer() update_schema_serializer = UpdateSchemaSerializer() resolved_schemas_serializer = ResolvedSchemaSerializer()