fix: exclude hardcoded qs from dynamic table

This commit is contained in:
James Graham
2021-03-10 11:38:52 +00:00
parent 8697d726b6
commit df13bcf46d
2 changed files with 4 additions and 4 deletions

View File

@@ -109,12 +109,12 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
def build_question_answers(self, answer_set: models.OrganisationAnswerSet) -> typing.Dict[str, str]: def build_question_answers(self, answer_set: models.OrganisationAnswerSet) -> typing.Dict[str, str]:
"""Collect answers to dynamic questions and join with commas.""" """Collect answers to dynamic questions and join with commas."""
show_all = self.request.user.is_superuser show_all = self.request.user.is_superuser
questions = models.OrganisationQuestion.objects.all() questions = models.OrganisationQuestion.objects.filter(is_hardcoded=False)
if not show_all: if not show_all:
questions = questions.filter(answer_is_public=True) questions = questions.filter(answer_is_public=True)
question_answers = {} question_answers = {}
for question in models.OrganisationQuestion.objects.all(): for question in questions:
answers = answer_set.question_answers.filter(question=question) answers = answer_set.question_answers.filter(question=question)
question_answers[str(question)] = ', '.join(map(str, answers)) question_answers[str(question)] = ', '.join(map(str, answers))

View File

@@ -74,12 +74,12 @@ class ProfileView(LoginRequiredMixin, DetailView):
def build_question_answers(self, answer_set: models.PersonAnswerSet) -> typing.Dict[str, str]: def build_question_answers(self, answer_set: models.PersonAnswerSet) -> typing.Dict[str, str]:
"""Collect answers to dynamic questions and join with commas.""" """Collect answers to dynamic questions and join with commas."""
show_all = (self.object.user == self.request.user) or self.request.user.is_superuser show_all = (self.object.user == self.request.user) or self.request.user.is_superuser
questions = models.PersonQuestion.objects.all() questions = models.PersonQuestion.objects.filter(is_hardcoded=False)
if not show_all: if not show_all:
questions = questions.filter(answer_is_public=True) questions = questions.filter(answer_is_public=True)
question_answers = {} question_answers = {}
for question in models.PersonQuestion.objects.all(): for question in questions:
answers = answer_set.question_answers.filter(question=question) answers = answer_set.question_answers.filter(question=question)
question_answers[str(question)] = ', '.join(map(str, answers)) question_answers[str(question)] = ', '.join(map(str, answers))