Skip to content

Commit

Permalink
schema: adding support for multiple location names
Browse files Browse the repository at this point in the history
  • Loading branch information
M3nin0 committed Feb 15, 2024
1 parent ff9d654 commit 1f547c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion invenio_geographic_identifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

from .ext import InvenioGeographicIdentifiers

__version__ = "0.3.0"
__version__ = "0.4.0"
__all__ = ("__version__", "InvenioGeographicIdentifiers")
18 changes: 14 additions & 4 deletions invenio_geographic_identifiers/contrib/geonames/datastreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

"""Geonames datastreams."""

from itertools import chain

from invenio_access.permissions import system_identity
from invenio_vocabularies.datastreams.transformers import BaseTransformer
from invenio_vocabularies.datastreams.writers import ServiceWriter
Expand All @@ -26,10 +28,18 @@ def apply(self, stream_entry, *args, **kwargs):
stream_entry.entry = {
"id": f"geonames::{stream_entry.entry['geonameid']}",
"scheme": "geonames",
"name": (
stream_entry.entry.get("asciiname")
or stream_entry.entry.get("name")
or stream_entry.entry.get("alternativenames")
"name": list(
chain(
*list(
filter(
lambda x: x is not None,
map(
lambda y: stream_entry.entry.get(y),
["asciiname", "name", "alternativenames"],
),
)
)
)
),
"locations": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
},
"name": {
"description": "Human readable label.",
"type": "string"
"type": "array",
"items": {
"type": "string"
}
},
"locations": {
"type": "array",
Expand Down
2 changes: 1 addition & 1 deletion invenio_geographic_identifiers/geoidentifiers/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GeographicIdentifiersSchema(BaseVocabularySchema):
# (subjects)``, here the ``id`` is ``required``
id = SanitizedUnicode(required=True)
scheme = SanitizedUnicode(required=True)
name = SanitizedUnicode(required=True)
name = fields.List(required=True, cls_or_instance=SanitizedUnicode(required=True))
locations = fields.List(
required=True, cls_or_instance=fields.Nested(LocationSchema)
)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ install_requires =
docs =
Sphinx>=4.5.0
tests =
black<=23.12.1
pytest-black>=0.3.0
invenio-app>=1.3.4,<2.0.0
invenio-db[postgresql,mysql]>=1.0.14,<2.0.0
Expand Down

0 comments on commit 1f547c2

Please sign in to comment.