Skip to content

Commit

Permalink
Add logic to add, remove, and view CRediT records
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPaulEve committed Dec 3, 2024
1 parent 56f3b0c commit 22aaba0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,17 @@ def snapshot_self(self, article, force_update=True):
credit_record.frozen_author = fa
credit_record.save()

def credits(self, article):
"""
Returns the CRediT records for this user on a given article
"""
return submission_models.CreditRecord.objects.filter(article=article,
author=self)

def add_credit(self, credit_role_text, article):
"""
Adds a CRediT role to the article for this user
"""
record, _ = (
submission_models.CreditRecord.objects.get_or_create(
article=article, author=self, role=credit_role_text)
Expand All @@ -607,14 +617,18 @@ def add_credit(self, credit_role_text, article):
return record

def remove_credit(self, credit_role_text, article):
record, _ = (
submission_models.CreditRecord.objects.get_or_create(
article=article, author=self, role=credit_role_text)
)

record.delete()
"""
Removes a CRediT role from the article for this user
"""
try:
record, _ = (
submission_models.CreditRecord.objects.get(
article=article, author=self, role=credit_role_text)
)

return record
record.delete()
except submission_models.CreditRecord.DoesNotExist:
pass

def frozen_author(self, article):
try:
Expand Down
31 changes: 31 additions & 0 deletions src/submission/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,37 @@ class Meta:
def __str__(self):
return self.full_name()

def credits(self, article):
"""
Returns all the credit records for this frozen author on a given article
"""
return CreditRecord.objects.filter(article=article, frozen_author=self)

def add_credit(self, credit_role_text, article):
"""
Adds a credit role to the article for this frozen author
"""
record, _ = (
CreditRecord.objects.get_or_create(
article=article, frozen_author=self, role=credit_role_text)
)

return record

def remove_credit(self, credit_role_text, article):
"""
Removes a credit role from the article for this frozen author
"""
try:
record, _ = (
CreditRecord.objects.get(
article=article, frozen_author=self, role=credit_role_text)
)

record.delete()
except CreditRecord.DoesNotExist:
pass

def full_name(self):
if self.is_corporate:
return self.corporate_name
Expand Down

0 comments on commit 22aaba0

Please sign in to comment.