Skip to content

Commit

Permalink
Add is_latest to paper serializer versions
Browse files Browse the repository at this point in the history
  • Loading branch information
koutst committed Oct 28, 2024
1 parent ad71b26 commit 24b70e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/paper/serializers/paper_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,16 @@ def get_version_list(self, paper) -> list:
paper_versions = PaperVersion.objects.filter(
base_doi=paper_version.base_doi
).order_by("version")
latest_version = paper_versions.last()

# Return a list of version pointing to the paper_id
return [
{
"version": version.version,
"paper_id": version.paper.id,
"published_date": paper.paper_publish_date,
"message": version.message,
"is_latest": version.version == latest_version.version,
}
for version in paper_versions
]
Expand Down Expand Up @@ -1087,13 +1090,16 @@ def get_version_list(self, paper) -> list:
paper_versions = PaperVersion.objects.filter(
base_doi=paper_version.base_doi
).order_by("version")
latest_version = paper_versions.last()

# Return a list of version pointing to the paper_id
return [
{
"version": version.version,
"paper_id": version.paper.id,
"published_date": paper.paper_publish_date,
"message": version.message,
"is_latest": version.version == latest_version.version,
}
for version in paper_versions
]
Expand Down
6 changes: 6 additions & 0 deletions src/paper/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_paper_serializer_paper_versions(self):
"paper_id": paper.id,
"message": "Test Message",
"published_date": paper.paper_publish_date,
"is_latest": True,
}
],
)
Expand All @@ -64,12 +65,14 @@ def test_paper_serializer_paper_versions(self):
"paper_id": paper.id,
"message": "Test Message",
"published_date": paper.paper_publish_date,
"is_latest": False,
},
{
"version": 2,
"paper_id": paper2.id,
"message": "Test Message 2",
"published_date": paper2.paper_publish_date,
"is_latest": True,
},
],
)
Expand All @@ -90,6 +93,7 @@ def test_dynamic_paper_serializer_paper_versions(self):
"paper_id": paper.id,
"message": "Test Message",
"published_date": paper.paper_publish_date,
"is_latest": True,
}
],
)
Expand All @@ -110,12 +114,14 @@ def test_dynamic_paper_serializer_paper_versions(self):
"paper_id": paper.id,
"message": "Test Message",
"published_date": paper.paper_publish_date,
"is_latest": False,
},
{
"version": 2,
"paper_id": paper2.id,
"message": "Test Message 2",
"published_date": paper2.paper_publish_date,
"is_latest": True,
},
],
)

0 comments on commit 24b70e8

Please sign in to comment.