Skip to content

Commit

Permalink
only look up the answer view response type once
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Apr 30, 2024
1 parent b6e63b4 commit 27adc39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions crowdsourcer/views/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ def check_permissions(self):
raise PermissionDenied

def process_form(self, form):
rt = ResponseType.objects.get(type=self.response_type)
cleaned_data = form.cleaned_data
# XXX work out what the field is
if (
cleaned_data.get("option", None) is not None
or len(list(cleaned_data.get("multi_option", None))) > 0
):
form.instance.response_type = rt
form.instance.response_type = self.rt
form.instance.user = self.request.user
form.save()
logger.debug(f"saved form {form.prefix}")
Expand Down
10 changes: 8 additions & 2 deletions crowdsourcer/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ class BaseQuestionView(CurrentStateMixin, TemplateView):
title_start = ""
how_marked_in = ["volunteer", "national_volunteer"]

def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
try:
self.rt = ResponseType.objects.get(type=self.response_type)
except ResponseType.DoesNotExist:
self.rt = None

def get_initial_obj(self):
rt = ResponseType.objects.get(type=self.response_type)
self.authority = PublicAuthority.objects.get(name=self.kwargs["name"])
self.questions = Question.objects.filter(
section__title=self.kwargs["section_title"],
questiongroup=self.authority.questiongroup,
how_marked__in=self.how_marked_in,
).order_by("number", "number_part")
responses = Response.objects.filter(
authority=self.authority, question__in=self.questions, response_type=rt
authority=self.authority, question__in=self.questions, response_type=self.rt
).select_related("question")

initial = {}
Expand Down
3 changes: 1 addition & 2 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,12 @@ def get_initial_obj(self):
return super().get_initial_obj()

def process_form(self, form):
rt = ResponseType.objects.get(type="First Mark")
cleaned_data = form.cleaned_data
if (
cleaned_data.get("option", None) is not None
or len(list(cleaned_data.get("multi_option", None))) > 0
):
form.instance.response_type = rt
form.instance.response_type = self.rt
form.instance.user = self.request.user
form.save()
logger.debug(f"saved form {form.prefix}")
Expand Down

0 comments on commit 27adc39

Please sign in to comment.