Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace toggle_no_grades with an idempotent alternative #2040

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions evap/grades/templates/grades_semester_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ <h3 class="col-8 mb-0">
{% include 'confirmation_modal.html' with modal_id='confirmNouploadModal' title=title question=question action_text=action_text btn_type='primary' %}
<script type="text/javascript">
function confirmNouploadModalAction(dataId) {
fetch("{% url 'grades:toggle_no_grades' %}", {
body: new URLSearchParams({course_id: dataId}),
confirmUploadModalAction(dataId, true);
}

function confirmUploadModalAction(dataId, status) {
niklasmohrin marked this conversation as resolved.
Show resolved Hide resolved
fetch("{% url 'grades:set_no_grades'%}", {
body: new URLSearchParams({course_id: dataId, status: `${Number(status)}` }),
headers: CSRF_HEADERS,
method: "POST",
}).then(response => {
Expand All @@ -124,7 +128,7 @@ <h3 class="col-8 mb-0">
{% include 'confirmation_modal.html' with modal_id='confirmLateruploadModal' title=title question=question action_text=action_text btn_type='primary' %}
<script type="text/javascript">
function confirmLateruploadModalAction(dataId) {
confirmNouploadModalAction(dataId);
confirmUploadModalAction(dataId, false);
};
</script>
{% endblock %}
Expand Down
10 changes: 5 additions & 5 deletions evap/grades/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
niklasmohrin marked this conversation as resolved.
Show resolved Hide resolved
def test_set_no_grades(self):
evaluation = self.evaluation
evaluation.manager_approve()
evaluation.begin_evaluation()
Expand All @@ -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,
)
Expand All @@ -160,8 +160,8 @@ 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,
)
Expand Down
2 changes: 1 addition & 1 deletion evap/grades/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
path("grade_document/<int:grade_document_id>/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"),
]
12 changes: 9 additions & 3 deletions evap/grades/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -146,12 +146,18 @@

@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

Check warning on line 155 in evap/grades/views.py

View check run for this annotation

Codecov / codecov/patch

evap/grades/views.py#L154-L155

Added lines #L154 - L155 were not covered by tests

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:
Expand Down