Skip to content

Commit

Permalink
schemas: add SimplifiedSchemaSerializer
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Trzcinska <[email protected]>
  • Loading branch information
annatrz committed Nov 15, 2019
1 parent 11b6c36 commit 0c9e87c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cap/modules/records/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 12 additions & 2 deletions cap/modules/schemas/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""

Expand All @@ -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()

0 comments on commit 0c9e87c

Please sign in to comment.