Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serializers: added locations to ui serializer. #1453

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", [])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locations is an object with a single key "features" :

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

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