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

@@ -49,7 +49,7 @@
{% endif %}
{% include 'people/person/includes/answer_set_full.html' %}
{% include 'people/person/includes/answer_set.html' %}
<a class="btn btn-success"
href="{% url 'people:person.update' pk=person.pk %}">Update</a>

View File

@@ -41,7 +41,7 @@
<hr>
{% include 'people/person/includes/answer_set_partial.html' %}
{% include 'people/person/includes/answer_set.html' %}
<hr>

View File

@@ -0,0 +1,25 @@
<table class="table table-borderless">
<thead>
<tr>
<th width="50%">Question</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
{% for question, answers in question_answers.items %}
<tr>
<td>{{ question }}</td>
<td>{{ answers }}</td>
</tr>
{% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody>
</table>
<p>Last updated: {{ answer_set.timestamp }}</p>

View File

@@ -1,57 +0,0 @@
<table class="table table-borderless">
<thead>
<tr>
<th width="50%">Question</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
{% if answer_set.nationality %}
<tr><td>Nationality</td><td>{{ answer_set.nationality.name }}</td>
{% endif %}
{% if answer_set.country_of_residence %}
<tr><td>Country of Residence</td><td>{{ answer_set.country_of_residence.name }}</td></tr>
{% endif %}
{% if answer_set.organisation %}
<tr><td>Organisation</td><td>{{ answer_set.organisation }}</td></tr>
{% endif %}
{% if answer_set.organisation_started_date %}
<tr><td>Organisation Started Date</td><td>{{ answer_set.organisation_started_date }}</td></tr>
{% endif %}
{% if answer_set.project_started_date %}
<tr><td>{{ settings.PARENT_PROJECT_NAME }} Started Date</td><td>{{ answer_set.project_started_date }}</td></tr>
{% endif %}
{% if answer_set.job_title %}
<tr><td>Job Title</td><td>{{ answer_set.job_title }}</td></tr>
{% endif %}
{% if answer_set.disciplinary_background %}
<tr><td>Disciplinary Background</td><td>{{ answer_set.disciplinary_background }}</td></tr>
{% endif %}
{% if answer_set.external_organisations %}
<tr><td>External Organisations Worked With</td><td>{{ answer_set.external_organisations }}</td></tr>
{% endif %}
{% for question, answers in question_answers.items %}
<tr>
<td>{{ question }}</td>
<td>{{ answers }}</td>
</tr>
{% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody>
</table>
<p>Last updated: {{ answer_set.timestamp }}</p>

View File

@@ -1,37 +0,0 @@
<table class="table table-borderless">
<thead>
<tr>
<th width="50%">Question</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
{% if answer_set.country_of_residence %}
<tr><td>Country of Residence</td><td>{{ answer_set.country_of_residence.name }}</td></tr>
{% endif %}
{% if answer_set.organisation %}
<tr><td>Organisation</td><td>{{ answer_set.organisation }}</td></tr>
{% endif %}
{% if answer_set.disciplinary_background %}
<tr><td>Disciplinary Background</td><td>{{ answer_set.disciplinary_background }}</td></tr>
{% endif %}
{% for question, answers in question_answers.items %}
<tr>
<td>{{ question }}</td>
<td>{{ answers }}</td>
</tr>
{% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody>
</table>
<p>Last updated: {{ answer_set.timestamp }}</p>

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