From 8614912a09b7a6059ea4447a56709d8eabbf41c1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 25 Apr 2024 16:23:32 +0100 Subject: [PATCH] miscelaneous view updates to respect marking sessions --- crowdsourcer/views/base.py | 1 - crowdsourcer/views/marking.py | 5 +++-- crowdsourcer/views/progress.py | 18 +++++++++++++----- crowdsourcer/views/stats.py | 32 +++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/crowdsourcer/views/base.py b/crowdsourcer/views/base.py index 74430174..c23f3d9d 100644 --- a/crowdsourcer/views/base.py +++ b/crowdsourcer/views/base.py @@ -9,7 +9,6 @@ from crowdsourcer.mixins import CurrentStateMixin from crowdsourcer.models import ( Assigned, - MarkingSession, PublicAuthority, Question, Response, diff --git a/crowdsourcer/views/marking.py b/crowdsourcer/views/marking.py index 643368e5..90afe57b 100644 --- a/crowdsourcer/views/marking.py +++ b/crowdsourcer/views/marking.py @@ -232,9 +232,9 @@ def get_queryset(self): return None question = Question.objects.get( - section__marking_session=self.current_session, + number=self.kwargs["number"], section__title=self.kwargs["section_title"], - marking_session=self.current_session, + section__marking_session=self.current_session, ) return PublicAuthority.objects.filter( questiongroup__question=question @@ -311,6 +311,7 @@ def get_redirect_url(self, *args, **kwargs): authority__name=self.kwargs["name"], question__number=self.kwargs["number"], question__section__title=self.kwargs["section_title"], + question__section__marking_session=self.current_session, ) except Response.DoesNotExist: return reverse("authority_question_answer", kwargs=kwargs) diff --git a/crowdsourcer/views/progress.py b/crowdsourcer/views/progress.py index 10bc11a9..9897a0cf 100644 --- a/crowdsourcer/views/progress.py +++ b/crowdsourcer/views/progress.py @@ -12,7 +12,6 @@ from crowdsourcer.models import ( Assigned, Marker, - MarkingSession, PublicAuthority, Question, Response, @@ -320,7 +319,7 @@ def test_func(self): return self.request.user.is_superuser def get_queryset(self): - return Assigned.objects.all() + return Assigned.objects.filter(marking_session=self.current_session) def render_to_response(self, context, **response_kwargs): response = HttpResponse(content_type="text/csv") @@ -378,7 +377,9 @@ def get_queryset(self): .annotate( has_logged_in=Subquery( Marker.objects.filter( - authority=OuterRef("pk"), response_type__type="Right of Reply" + authority=OuterRef("pk"), + response_type__type="Right of Reply", + marking_session=self.current_session, ) .order_by("-user__last_login") .values("user__last_login")[:1] @@ -386,6 +387,7 @@ def get_queryset(self): multi_has_logged_in=Subquery( Assigned.objects.filter( authority=OuterRef("pk"), + marking_session=self.current_session, user__marker__response_type__type="Right of Reply", ) .order_by("-user__last_login") @@ -406,6 +408,9 @@ class AllSectionChallengeView(CurrentStateMixin, UserPassesTestMixin, ListView): def test_func(self): return self.request.user.is_superuser + def get_queryset(self): + return Section.objects.filter(marking_session=self.current_session) + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -475,7 +480,8 @@ def test_func(self): def get_queryset(self): return Marker.objects.filter( - response_type__type="Right of Reply" + response_type__type="Right of Reply", + marking_session=self.current_session, ).select_related("user") def get_context_data(self, **kwargs): @@ -492,7 +498,9 @@ def get_context_data(self, **kwargs): "name": f"{marker.user.first_name} {marker.user.last_name}", } ) - assigned = Assigned.objects.filter(user=marker.user).all() + assigned = Assigned.objects.filter( + user=marker.user, marking_session=self.current_session + ).all() if assigned: for assignment in assigned: contacts.append( diff --git a/crowdsourcer/views/stats.py b/crowdsourcer/views/stats.py index 62feaa10..fbfcf387 100644 --- a/crowdsourcer/views/stats.py +++ b/crowdsourcer/views/stats.py @@ -34,7 +34,10 @@ def test_func(self): def get_queryset(self): return ( - Response.objects.filter(response_type__type=self.response_type) + Response.objects.filter( + response_type__type=self.response_type, + question__section__marking_session=self.current_session, + ) .select_related("question", "authority", "question__section", "option") .order_by( "authority", @@ -65,8 +68,8 @@ def get_context_data(self, **kwargs): responses = defaultdict(dict) questions = ( - Question.objects.select_related("section") - .all() + Question.objects.filter(section__marking_session=self.current_session) + .select_related("section") .order_by("section__title", "number", "number_part") ) @@ -504,18 +507,24 @@ def test_func(self): return self.request.user.is_superuser def get_queryset(self): - return Option.objects.select_related("question", "question__section").order_by( - "question__section__title", - "question__number", - "question__number_part", - "score", + return ( + Option.objects.filter( + question__section__marking_session=self.current_session + ) + .select_related("question", "question__section") + .order_by( + "question__section__title", + "question__number", + "question__number_part", + "score", + ) ) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) scoring = {} - get_section_maxes(scoring) + get_section_maxes(scoring, self.current_session) sections = defaultdict(dict) for option in context["options"]: @@ -607,6 +616,7 @@ def get_queryset(self): response_type__type="Audit", option__isnull=True, multi_option__isnull=True, + question__section__marking_session=self.current_session, ) .select_related("authority", "question", "question__section") .order_by("authority", "question__section") @@ -623,7 +633,7 @@ def test_func(self): return self.request.user.is_superuser def get_queryset(self): - return get_duplicate_responses() + return get_duplicate_responses(self.current_session) def get_context_data(self, **kwargs): ignore_exacts = self.request.GET.get("ignore_exacts", 0) @@ -631,7 +641,7 @@ def get_context_data(self, **kwargs): duplicates = context["responses"] - exact_duplicates = get_exact_duplicates(duplicates) + exact_duplicates = get_exact_duplicates(duplicates, self.current_session) exact_ids = [] for exact in exact_duplicates: