From 699da05b04633d991249d1226ea8c06ce77bdcbb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 Dec 2024 10:10:13 +0000 Subject: [PATCH] make sure authority and section exist on marking page --- crowdsourcer/views/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crowdsourcer/views/base.py b/crowdsourcer/views/base.py index eac44b6..2873856 100644 --- a/crowdsourcer/views/base.py +++ b/crowdsourcer/views/base.py @@ -10,6 +10,7 @@ from django.db.models.functions import Cast from django.dispatch import receiver from django.http import JsonResponse +from django.shortcuts import get_object_or_404 from django.views.generic import ListView, TemplateView from crowdsourcer.forms import ResponseForm, ResponseFormset @@ -97,10 +98,14 @@ def add_previous(self, initial, rt): return initial def get_initial_obj(self): - self.authority = PublicAuthority.objects.get(name=self.kwargs["name"]) + self.authority = get_object_or_404(PublicAuthority, name=self.kwargs["name"]) + section = get_object_or_404( + Section, + title=self.kwargs["section_title"], + marking_session=self.request.current_session, + ) self.questions = Question.objects.filter( - section__marking_session=self.request.current_session, - section__title=self.kwargs["section_title"], + section=section, questiongroup=self.authority.questiongroup, how_marked__in=self.how_marked_in, ).order_by("number", "number_part")