Skip to content

Commit

Permalink
set fields of read_only questions to disabled
Browse files Browse the repository at this point in the history
easier to do this as then the form validation knows to ignore them
  • Loading branch information
struan committed Dec 10, 2024
1 parent 2ab1536 commit e168143
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crowdsourcer/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BaseQuestionView(TemplateView):
title_start = ""
how_marked_in = ["volunteer", "national_volunteer"]
has_previous_questions = False
read_only_questions = True

def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
Expand Down Expand Up @@ -193,7 +194,16 @@ def post(self, *args, **kwargs):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["form"] = self.get_form()
form = self.get_form()

if self.read_only_questions and not self.request.user.is_superuser:
for q_form in form:
if q_form.question_obj.read_only:
for name, field in q_form.fields.items():
field.disabled = True
q_form.fields[name] = field

context["form"] = form
context["section_title"] = self.kwargs.get("section_title", "")
context["authority"] = PublicAuthority.objects.get(
name=self.kwargs.get("name", "")
Expand Down
1 change: 1 addition & 0 deletions crowdsourcer/views/rightofreply.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class AuthorityRORSectionQuestions(BaseQuestionView):
log_start = "ROR form"
title_start = "Right of Reply - "
how_marked_in = ["volunteer", "national_volunteer", "foi"]
read_only_questions = False

def get_template_names(self):
if self.has_previous_questions:
Expand Down

0 comments on commit e168143

Please sign in to comment.