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

#362 Added ror field to default article serializer and to legacy article s… #220

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
14 changes: 14 additions & 0 deletions scoap3/articles/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CopyrightSerializer,
PublicationInfoSerializer,
)
from scoap3.misc.models import InstitutionIdentifierType


class ArticleFileSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -105,6 +106,19 @@ def get_metadata(self, obj):
else None,
"organization": affiliation.organization,
"value": affiliation.value,
**(
{
"ror": affiliation.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
)
.values_list("identifier_value", flat=True)
.first(),
}
if affiliation.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
).exists()
else {}
),
}
for affiliation in entry.affiliations.all()
],
Expand Down
20 changes: 19 additions & 1 deletion scoap3/articles/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

from scoap3.articles.models import Article, ArticleFile, ArticleIdentifier
from scoap3.authors.models import Author, AuthorIdentifierType
from scoap3.misc.models import Affiliation, ArticleArxivCategory, PublicationInfo
from scoap3.misc.models import (
Affiliation,
ArticleArxivCategory,
InstitutionIdentifierType,
PublicationInfo,
)


@registry.register_document
Expand Down Expand Up @@ -136,6 +141,19 @@ def prepare_authors(self, instance):
"value": affiliation.value,
"organization": affiliation.organization,
"country": country,
**(
{
"ror": affiliation.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
)
.values_list("identifier_value", flat=True)
.first(),
}
if affiliation.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
).exists()
else {}
),
}
serialized_affiliations.append(serialized_affiliation)

Expand Down
1 change: 1 addition & 0 deletions scoap3/articles/tests/test_record_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_get_record_json_structure_nested(self, client, license, user):
assert "country" in affiliation
assert "organization" in affiliation
assert "value" in affiliation
assert "ror" in affiliation

assert "collections" in metadata
collections = metadata["collections"]
Expand Down
17 changes: 17 additions & 0 deletions scoap3/misc/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ExperimentalCollaboration,
Funder,
InstitutionIdentifier,
InstitutionIdentifierType,
License,
PublicationInfo,
Publisher,
Expand All @@ -22,10 +23,26 @@ class Meta:


class AffiliationSerializer(serializers.ModelSerializer):
ror = serializers.SerializerMethodField()

class Meta:
model = Affiliation
fields = "__all__"

def get_ror(self, obj):
if obj.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
).exists():
return (
obj.institutionidentifier_set.filter(
identifier_type=InstitutionIdentifierType.ROR
)
.values_list("identifier_value", flat=True)
.first()
)
else:
return None


class InstitutionIdentifierSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
Loading