From 72317965e5f0de8f89fd4de364323a65cbcae826 Mon Sep 17 00:00:00 2001 From: xaralis Date: Mon, 11 Jan 2021 10:53:51 +0100 Subject: [PATCH] fix: accidental delets with solution submission form --- ksicht/core/views/submissions.py | 17 +++++------------ ksicht/forms.py | 17 ++--------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/ksicht/core/views/submissions.py b/ksicht/core/views/submissions.py index c5f9ebe..2cef944 100644 --- a/ksicht/core/views/submissions.py +++ b/ksicht/core/views/submissions.py @@ -18,15 +18,7 @@ from ksicht import pdf from ksicht.pdf import ensure_file_valid from .. import forms -from ..models import ( - Grade, - GradeApplication, - GradeSeries, - Participant, - Sticker, - Task, - TaskSolutionSubmission, -) +from ..models import Grade, GradeApplication, GradeSeries, Participant, Sticker, Task, TaskSolutionSubmission from .decorators import current_grade_exists, is_participant @@ -173,7 +165,8 @@ def get_form_kwargs(self): submission_map[participant.user_id][task.id] = None for s in TaskSolutionSubmission.objects.filter( - application__grade=self.grade + application__grade=self.grade, + task__series=self.series, ).select_related("task", "application"): submission_map[s.application.participant_id][s.task.id] = s @@ -207,7 +200,8 @@ def _build_initial(participant): def form_valid(self, form): submissions = TaskSolutionSubmission.objects.filter( - application__grade=self.grade + application__grade=self.grade, + task__series=self.series, ) applications = GradeApplication.objects.filter(grade=self.grade) @@ -235,7 +229,6 @@ def form_valid(self, form): overdue_submissions = saved_submissions - desired_submissions to_create = [] - to_remove = [] # Handle submissions to create for s in missing_submissions: diff --git a/ksicht/forms.py b/ksicht/forms.py index 9a0670d..6afb64d 100644 --- a/ksicht/forms.py +++ b/ksicht/forms.py @@ -1,26 +1,13 @@ from crispy_forms.helper import FormHelper from cuser.forms import AuthenticationForm, UserChangeForm, UserCreationForm from django import forms -from django.contrib.auth.forms import ( - PasswordChangeForm, - PasswordResetForm, - SetPasswordForm, -) +from django.contrib.auth.forms import PasswordChangeForm, PasswordResetForm, SetPasswordForm from django.core import validators from django_registration import validators as reg_validators import pydash as py_ from webpack_loader.templatetags.webpack_loader import webpack_static -from ksicht.bulma.layout import ( - Column, - Field, - FormActions, - FormControl, - Layout, - Link, - Row, - Submit, -) +from ksicht.bulma.layout import Column, Field, FormActions, FormControl, Layout, Link, Row, Submit from ksicht.core import constants from ksicht.core.models import Grade, Participant, User