Skip to content

Commit

Permalink
Issue #351 ORCID in serializer
Browse files Browse the repository at this point in the history
Added the ORCID fields to /articles and /records by updating the article serializer and the legacy article serializer
  • Loading branch information
Lorenzovagliano committed Sep 19, 2024
1 parent ed62f14 commit 6399047
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
12 changes: 10 additions & 2 deletions scoap3/articles/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ArticleIdentifierType,
)
from scoap3.authors.api.serializers import AuthorSerializer
from scoap3.authors.models import AuthorIdentifierType
from scoap3.misc.api.serializers import (
ArticleArxivCategorySerializer,
CopyrightSerializer,
Expand Down Expand Up @@ -56,8 +57,8 @@ def to_representation(self, instance):
class LegacyArticleSerializer(serializers.ModelSerializer):
metadata = serializers.SerializerMethodField()
updated = serializers.SerializerMethodField()
created = serializers.SerializerMethodField()
id = serializers.SerializerMethodField()
created = serializers.SerializerMethodField()

class Meta:
model = Article
Expand All @@ -72,7 +73,6 @@ def get_metadata(self, obj):
{
"filetype": entry.file.type,
"size": entry.file.size,
"key": entry.file.name,
}
for entry in obj.related_files.all()
],
Expand Down Expand Up @@ -111,6 +111,14 @@ def get_metadata(self, obj):
"full_name": entry.full_name,
"given_names": entry.first_name,
"surname": entry.last_name,
"orcid": {
orcid
for orcid in entry.identifiers.filter(
identifier_type=AuthorIdentifierType.ORCID
)
.values_list("identifier_value", flat=True)
.all()
},
}
for entry in obj.authors.all()
],
Expand Down
13 changes: 12 additions & 1 deletion scoap3/authors/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from scoap3.authors.models import Author, AuthorIdentifier
from scoap3.authors.models import Author, AuthorIdentifier, AuthorIdentifierType
from scoap3.misc.api.serializers import AffiliationSerializer


Expand All @@ -12,7 +12,18 @@ class Meta:

class AuthorSerializer(serializers.ModelSerializer):
affiliations = AffiliationSerializer(many=True, read_only=True)
orcid = serializers.SerializerMethodField()

class Meta:
model = Author
fields = "__all__"

def get_orcid(self, obj):
return {
orcid
for orcid in obj.identifiers.filter(
identifier_type=AuthorIdentifierType.ORCID
)
.values_list("identifier_value", flat=True)
.all()
}
2 changes: 1 addition & 1 deletion scoap3/authors/migrations/0005_alter_author_article_id.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2024-09-18 12:55
# Generated by Django 4.2.5 on 2024-09-16 15:12

from django.db import migrations, models
import django.db.models.deletion
Expand Down
2 changes: 1 addition & 1 deletion scoap3/misc/migrations/0020_alter_affiliation_author_id.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2024-09-18 12:55
# Generated by Django 4.2.5 on 2024-09-16 15:12

from django.db import migrations, models

Expand Down

0 comments on commit 6399047

Please sign in to comment.