From 253fc3311ac51dd2b9723c5e99b25fb819d224bb Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Fri, 20 Sep 2024 12:23:58 +0200 Subject: [PATCH] improve typehints for profile and submission --- scipost_django/profiles/models.py | 15 +++++++++------ scipost_django/scipost/models.py | 4 +++- scipost_django/submissions/models/submission.py | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scipost_django/profiles/models.py b/scipost_django/profiles/models.py index 37b45132a..fb4bc5fae 100644 --- a/scipost_django/profiles/models.py +++ b/scipost_django/profiles/models.py @@ -126,10 +126,17 @@ class Profile(models.Model): @property def full_name(self): + """The full name: first name + last name.""" return f"{self.first_name} {self.last_name}" + @property + def formal_name(self): + """The formal name: title + last name.""" + return f"{self.get_title_display()} {self.last_name}" + @property def full_name_original(self): + """The full name in original script: first name + last name.""" return f"{self.first_name_original} {self.last_name_original}" @property @@ -154,14 +161,10 @@ class Profile(models.Model): @property def has_active_contributor(self): - has_active_contributor = False try: - has_active_contributor = ( - self.contributor is not None and self.contributor.is_active - ) + return self.contributor is not None and self.contributor.is_active except Contributor.DoesNotExist: - pass - return has_active_contributor + return False def get_absolute_url(self): return reverse("profiles:profile_detail", kwargs={"pk": self.id}) diff --git a/scipost_django/scipost/models.py b/scipost_django/scipost/models.py index 5587a2aa0..e42cb6241 100644 --- a/scipost_django/scipost/models.py +++ b/scipost_django/scipost/models.py @@ -157,7 +157,9 @@ class Contributor(models.Model): Checks if the Contributor is registered, vetted, and has not been deactivated for any reason. """ - return self.user.is_active and self.status == NORMAL_CONTRIBUTOR + # [TypeHint] Coerce to bool since `is_active` is a property of the `AbstractBaseUser` class. + user_active: bool = self.user.is_active + return user_active and self.status == NORMAL_CONTRIBUTOR @property def is_duplicate(self): diff --git a/scipost_django/submissions/models/submission.py b/scipost_django/submissions/models/submission.py index 3a58ab3f6..dc7c6dbae 100644 --- a/scipost_django/submissions/models/submission.py +++ b/scipost_django/submissions/models/submission.py @@ -47,13 +47,12 @@ from ..refereeing_cycles import ShortCycle, DirectCycle, RegularCycle if TYPE_CHECKING: from django.db.models.manager import RelatedManager - from submissions.models import EditorialDecision + from submissions.models import EditorialDecision, RefereeInvitation, Report from scipost.models import Contributor from journals.models import Journal, Publication from proceedings.models import Proceedings from iThenticate_report import iThenticateReport from ontology.models import AcademicField, Specialty, Topic - from ..models.referee_invitation import RefereeInvitation from series.models import Collection @@ -258,6 +257,7 @@ class Submission(models.Model): author_profiles: "RelatedManager[SubmissionAuthorProfile]" collections: "RelatedManager[Collection]" editorial_assignments: "RelatedManager[EditorialAssignment]" + reports: "RelatedManager[Report]" # Fields preprint = models.OneToOneField( -- GitLab