Skip to content

Commit

Permalink
miscelaneous view updates to respect marking sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Apr 25, 2024
1 parent 718c693 commit 8614912
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
1 change: 0 additions & 1 deletion crowdsourcer/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from crowdsourcer.mixins import CurrentStateMixin
from crowdsourcer.models import (
Assigned,
MarkingSession,
PublicAuthority,
Question,
Response,
Expand Down
5 changes: 3 additions & 2 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 13 additions & 5 deletions crowdsourcer/views/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from crowdsourcer.models import (
Assigned,
Marker,
MarkingSession,
PublicAuthority,
Question,
Response,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -378,14 +377,17 @@ 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]
),
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")
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down
32 changes: 21 additions & 11 deletions crowdsourcer/views/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
)

Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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")
Expand All @@ -623,15 +633,15 @@ 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)
context = super().get_context_data(**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:
Expand Down

0 comments on commit 8614912

Please sign in to comment.