SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 00e14b8b authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add minor static typing annotations and exceptions

parent 4dde6c4e
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from typing import List
from typing import TYPE_CHECKING
from django.db import models
from django.contrib.contenttypes.fields import GenericRelation
from django.urls import reverse
......@@ -43,6 +43,9 @@ from .utils import proofs_id_to_slug
from finances.models import WorkLog
from scipost.storage import SecureFileStorage
if TYPE_CHECKING:
from submissions.models import Submission
class ProductionUser(models.Model):
"""
......@@ -68,7 +71,7 @@ class ProductionUser(models.Model):
class ProductionStream(models.Model):
submission = models.OneToOneField(
submission = models.OneToOneField["Submission"](
"submissions.Submission",
on_delete=models.CASCADE,
related_name="production_stream",
......@@ -297,7 +300,7 @@ class ProofsRepository(models.Model):
(PROOFS_REPO_PRODUCTION_READY, "The repository is ready for production"),
)
stream = models.OneToOneField(
stream = models.OneToOneField["ProductionStream"](
ProductionStream,
on_delete=models.CASCADE,
related_name="proofs_repository",
......@@ -348,7 +351,11 @@ class ProofsRepository(models.Model):
a Selections paper, it is the flagship journal of the college.
"""
decision_journal = self.stream.submission.editorial_decision.for_journal
# Guard against null editorial decision
if not (decision := self.stream.submission.editorial_decision):
raise ValueError("No (non-deprecated) editorial decision exists")
decision_journal = decision.for_journal
if "Selections" in decision_journal.name:
paper_field = self.stream.submission.acad_field
......@@ -410,7 +417,7 @@ class ProofsRepository(models.Model):
)
@cached_property
def template_paths(self) -> List[str]:
def template_paths(self) -> list[str]:
"""
Return the list of paths to the various templates used for the proofs.
"""
......
......@@ -3,7 +3,7 @@ __license__ = "AGPL v3"
import datetime
from typing import List
from typing import TYPE_CHECKING
import feedparser
import uuid
......@@ -43,6 +43,9 @@ from ..exceptions import StageNotDefinedError
from ..managers import SubmissionQuerySet, SubmissionEventQuerySet
from ..refereeing_cycles import ShortCycle, DirectCycle, RegularCycle
if TYPE_CHECKING:
from submissions.models import EditorialDecision
class SubmissionAuthorProfile(models.Model):
submission = models.ForeignKey(
......@@ -942,7 +945,7 @@ class Submission(models.Model):
return list(set(fellows))
@property
def editorial_decision(self):
def editorial_decision(self) -> "EditorialDecision | None":
"""Returns the latest EditorialDecision (if it exists)."""
if self.editorialdecision_set.nondeprecated().exists():
return self.editorialdecision_set.nondeprecated().latest_version()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment