refactor: making static qs more admin configurable

This commit is contained in:
James Graham
2021-03-18 18:09:02 +00:00
parent c20b2b5a0a
commit 8093b23870
6 changed files with 39 additions and 101 deletions

View File

@@ -95,17 +95,24 @@ class ProfileView(LoginRequiredMixin, DetailView):
def build_question_answers(
self, answer_set: models.PersonAnswerSet) -> typing.Dict[str, str]:
"""Collect answers to dynamic questions and join with commas."""
show_all = (self.object.user
== self.request.user) or self.request.user.is_superuser
questions = models.PersonQuestion.objects.filter(is_hardcoded=False)
show_all = ((self.object.user == self.request.user)
or self.request.user.is_superuser)
questions = models.PersonQuestion.objects.all()
if not show_all:
questions = questions.filter(answer_is_public=True)
question_answers = {}
try:
for question in questions:
answers = answer_set.question_answers.filter(question=question)
question_answers[str(question)] = ', '.join(map(str, answers))
if question.is_hardcoded:
question_answers[str(question)] = getattr(
answer_set, question.text)
else:
answers = answer_set.question_answers.filter(
question=question)
question_answers[str(question)] = ', '.join(
map(str, answers))
except AttributeError:
# No AnswerSet yet