Verified Commit 4525b390 authored by Peter Stanko's avatar Peter Stanko
Browse files

Ignore cancelled submission

parent 2e575a98
......@@ -927,6 +927,19 @@ class Submission(db.Model, EntityBase):
# open to extension (state transition validation, ...)
self.state = new_state
@property
def is_cancelled(self) -> bool:
return self.state in [SubmissionState.CANCELLED, SubmissionState.ABORTED]
@property
def is_finished(self) -> bool:
return self.state in [SubmissionState.FINISHED, SubmissionState.ARCHIVED]
@property
def is_processed(self) -> bool:
return self.state in [SubmissionState.CREATED, SubmissionState.QUEUED,
SubmissionState.READY, SubmissionState.IN_PROGRESS]
def __init__(self, user: User, project: Project, parameters: dict = None,
review: 'Review' = None):
"""Creates a new submission instance
......
......@@ -148,7 +148,7 @@ class ProjectService(GeneralService):
return True
def _check_latest_submission(self, user: User):
latest_submission = self.get_latest_submission(user)
latest_submission = self.get_latest_submission(user, ignore_cancel=True)
if not latest_submission:
return True
latest_time = latest_submission.created_at
......@@ -165,10 +165,13 @@ class ProjectService(GeneralService):
raise errors.SubmissionDiffTimeError(self.project, diff_time, user=user)
return True
def get_latest_submission(self, user) -> Submission:
return Submission.query.filter((Submission.user == user) &
(Submission.project == self.project)) \
.order_by(Submission.created_at.desc()).first()
def get_latest_submission(self, user, ignore_cancel: bool=False) -> Submission:
query = Submission.query.filter(
(Submission.user == user) & (Submission.project == self.project))
if ignore_cancel:
query = query.filter((Submission.state != SubmissionState.CANCELLED) &
(SubmissionState != SubmissionState.ABORTED))
return query.order_by(Submission.created_at.desc()).first()
def find_all(self, course: Course) -> list:
"""List of all projects
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment