Skip to content

Commit

Permalink
serializers: added locations to ui serializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo committed Sep 8, 2023
1 parent 2e363f3 commit f845a24
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion invenio_rdm_records/resources/serializers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def get_locations(self, obj):
"""Get locations."""
locations = []

access_location = obj["metadata"].get("locations", [])
access_location = obj["metadata"].get("locations", {})

if not access_location:
return missing

Expand Down
31 changes: 31 additions & 0 deletions invenio_rdm_records/resources/serializers/ui/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,35 @@ class FundingSchema(Schema):
funder = fields.Nested(FunderL10NItemSchema)


class GeometrySchema(Schema):
"""Schema for geometry in the UI."""

type = fields.Str()
coordinates = fields.List(fields.Float())


class IdentifierSchema(Schema):
"""Schema for dumping identifier in the UI."""

scheme = fields.Str()
identifier = fields.Str()


class FeatureSchema(Schema):
"""Schema for dumping locations in the UI."""

place = SanitizedUnicode()
description = SanitizedUnicode()
geometry = fields.Nested(GeometrySchema)
identifiers = fields.List(fields.Nested(IdentifierSchema))


class LocationSchema(Schema):
"""Schema for dumping locations in the UI."""

features = fields.List(fields.Nested(FeatureSchema))


class MeetingSchema(Schema):
"""Schema for dumping 'meeting' custom field in the UI."""

Expand Down Expand Up @@ -325,6 +354,8 @@ class UIRecordSchema(BaseObjectSchema):

tombstone = fields.Nested(TombstoneSchema, attribute="tombstone")

locations = fields.Nested(LocationSchema, attribute="metadata.locations")

@pre_dump
def add_communities_permissions_and_roles(self, obj, **kwargs):
"""Inject current user's permission to community receiver."""
Expand Down
21 changes: 21 additions & 0 deletions tests/resources/serializers/test_ui_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def full_to_dict_record(full_record):
}
]

to_dict_record["metadata"]["locations"] = {
"features": [
{
"geometry": {"type": "Point", "coordinates": [6.05, 46.23333]},
"identifiers": [{"scheme": "geonames", "identifier": "2661235"}],
"place": "CERN",
"description": "Invenio birth place.",
},
]
}

_add_affiliation_name(to_dict_record["metadata"]["creators"])
_add_affiliation_name(to_dict_record["metadata"]["contributors"])

Expand Down Expand Up @@ -206,6 +217,16 @@ def test_ui_serializer(app, full_to_dict_record):
},
}
],
"locations": {
"features": [
{
"geometry": {"type": "Point", "coordinates": [6.05, 46.23333]},
"identifiers": [{"scheme": "geonames", "identifier": "2661235"}],
"place": "CERN",
"description": "Invenio birth place.",
},
]
},
}

serialized_record = UIJSONSerializer().dump_obj(full_to_dict_record)
Expand Down

0 comments on commit f845a24

Please sign in to comment.