diff --git a/evap/grades/templates/grades_semester_view.html b/evap/grades/templates/grades_semester_view.html index 0a026155f0..bc0d8d7153 100644 --- a/evap/grades/templates/grades_semester_view.html +++ b/evap/grades/templates/grades_semester_view.html @@ -108,8 +108,12 @@

{% include 'confirmation_modal.html' with modal_id='confirmNouploadModal' title=title question=question action_text=action_text btn_type='primary' %} {% endblock %} diff --git a/evap/grades/tests.py b/evap/grades/tests.py index c340009cf2..1e02bfc279 100644 --- a/evap/grades/tests.py +++ b/evap/grades/tests.py @@ -135,7 +135,7 @@ def test_upload_final_grades(self): evaluation.save() self.helper_check_final_grade_upload(course, 0) - def test_toggle_no_grades(self): + def test_set_no_grades(self): evaluation = self.evaluation evaluation.manager_approve() evaluation.begin_evaluation() @@ -146,8 +146,8 @@ def test_toggle_no_grades(self): self.assertFalse(evaluation.course.gets_no_grade_documents) self.app.post( - "/grades/toggle_no_grades", - params={"course_id": evaluation.course.id}, + "/grades/set_no_grades", + params={"course_id": evaluation.course.id, "status": "1"}, user=self.grade_publisher, status=200, ) @@ -160,8 +160,17 @@ def test_toggle_no_grades(self): ) self.app.post( - "/grades/toggle_no_grades", - params={"course_id": evaluation.course.id}, + "/grades/set_no_grades", + params={"course_id": evaluation.course.id, "status": "0"}, + user=self.grade_publisher, + status=200, + ) + evaluation = Evaluation.objects.get(id=evaluation.id) + self.assertFalse(evaluation.course.gets_no_grade_documents) + + self.app.post( + "/grades/set_no_grades", + params={"course_id": evaluation.course.id, "status": "0"}, user=self.grade_publisher, status=200, ) diff --git a/evap/grades/urls.py b/evap/grades/urls.py index 541d26e2cb..7fc0ad0bff 100644 --- a/evap/grades/urls.py +++ b/evap/grades/urls.py @@ -13,5 +13,5 @@ path("grade_document//edit", views.edit_grades, name="edit_grades"), path("delete_grades", views.delete_grades, name="delete_grades"), - path("toggle_no_grades", views.toggle_no_grades, name="toggle_no_grades"), + path("set_no_grades", views.set_no_grades, name="set_no_grades"), ] diff --git a/evap/grades/views.py b/evap/grades/views.py index 21f9f458ab..fa8b0a8119 100644 --- a/evap/grades/views.py +++ b/evap/grades/views.py @@ -1,6 +1,6 @@ from django.conf import settings from django.contrib import messages -from django.core.exceptions import PermissionDenied +from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.db.models.query import QuerySet from django.http import FileResponse, HttpResponse from django.shortcuts import get_object_or_404, redirect, render @@ -146,12 +146,18 @@ def upload_grades(request, course_id): @require_POST @grade_publisher_required -def toggle_no_grades(request): +def set_no_grades(request): course = get_object_from_dict_pk_entry_or_logged_40x(Course, request.POST, "course_id") + + try: + status = bool(int(request.POST["status"])) + except (KeyError, TypeError, ValueError) as e: + raise SuspiciousOperation from e + if course.semester.grade_documents_are_deleted: raise PermissionDenied - course.gets_no_grade_documents = not course.gets_no_grade_documents + course.gets_no_grade_documents = status course.save() if course.gets_no_grade_documents: