mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
fix: condense multiple answers to same question
Show on same row on profile page See #97
This commit is contained in:
@@ -56,22 +56,12 @@
|
|||||||
<tr><td>HQ Country</td><td>{{ answer_set.hq_country.name }}</td></tr>
|
<tr><td>HQ Country</td><td>{{ answer_set.hq_country.name }}</td></tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if request.user.is_superuser %}
|
{% for question, answers in question_answers.items %}
|
||||||
{% for answer in answer_set.question_answers.all %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ answer.question }}</td>
|
<td>{{ question }}</td>
|
||||||
<td>{{ answer }}</td>
|
<td>{{ answers }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% else %}
|
|
||||||
{% for answer in answer_set.public_answers.all %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ answer.question }}</td>
|
|
||||||
<td>{{ answer }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -31,15 +31,10 @@
|
|||||||
<tr><td>Job Title</td><td>{{ answer_set.job_title }}</td></tr>
|
<tr><td>Job Title</td><td>{{ answer_set.job_title }}</td></tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for answer in answer_set.question_answers.all %}
|
{% for question, answers in question_answers.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ answer.question }}</td>
|
<td>{{ question }}</td>
|
||||||
<td>{{ answer }}</td>
|
<td>{{ answers }}</td>
|
||||||
</tr>
|
|
||||||
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td>No records</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -15,15 +15,10 @@
|
|||||||
<tr><td>Organisation</td><td>{{ answer_set.organisation }}</td></tr>
|
<tr><td>Organisation</td><td>{{ answer_set.organisation }}</td></tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for answer in answer_set.public_answers.all %}
|
{% for question, answers in question_answers.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ answer.question }}</td>
|
<td>{{ question }}</td>
|
||||||
<td>{{ answer }}</td>
|
<td>{{ answers }}</td>
|
||||||
</tr>
|
|
||||||
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td>No records</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -106,6 +106,20 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
|
|||||||
context_object_name = 'organisation'
|
context_object_name = 'organisation'
|
||||||
template_name = 'people/organisation/detail.html'
|
template_name = 'people/organisation/detail.html'
|
||||||
|
|
||||||
|
def build_question_answers(self, answer_set: models.OrganisationAnswerSet) -> typing.Dict[str, str]:
|
||||||
|
"""Collect answers to dynamic questions and join with commas."""
|
||||||
|
show_all = self.request.user.is_superuser
|
||||||
|
questions = models.OrganisationQuestion.objects.all()
|
||||||
|
if not show_all:
|
||||||
|
questions = questions.filter(answer_is_public=True)
|
||||||
|
|
||||||
|
question_answers = {}
|
||||||
|
for question in models.OrganisationQuestion.objects.all():
|
||||||
|
answers = answer_set.question_answers.filter(question=question)
|
||||||
|
question_answers[str(question)] = ', '.join(map(str, answers))
|
||||||
|
|
||||||
|
return question_answers
|
||||||
|
|
||||||
def get_context_data(self,
|
def get_context_data(self,
|
||||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
"""Add map marker to context."""
|
"""Add map marker to context."""
|
||||||
@@ -113,6 +127,7 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
|
|||||||
|
|
||||||
answerset = self.object.current_answers
|
answerset = self.object.current_answers
|
||||||
context['answer_set'] = answerset
|
context['answer_set'] = answerset
|
||||||
|
context['question_answers'] = self.build_question_answers(answerset)
|
||||||
context['map_markers'] = [{
|
context['map_markers'] = [{
|
||||||
'name': self.object.name,
|
'name': self.object.name,
|
||||||
'lat': getattr(answerset, 'latitude', None),
|
'lat': getattr(answerset, 'latitude', None),
|
||||||
|
|||||||
@@ -71,12 +71,28 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
|||||||
# pk was not provided in URL
|
# pk was not provided in URL
|
||||||
return self.request.user.person
|
return self.request.user.person
|
||||||
|
|
||||||
|
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.all()
|
||||||
|
if not show_all:
|
||||||
|
questions = questions.filter(answer_is_public=True)
|
||||||
|
|
||||||
|
question_answers = {}
|
||||||
|
for question in models.PersonQuestion.objects.all():
|
||||||
|
answers = answer_set.question_answers.filter(question=question)
|
||||||
|
question_answers[str(question)] = ', '.join(map(str, answers))
|
||||||
|
|
||||||
|
return question_answers
|
||||||
|
|
||||||
def get_context_data(self,
|
def get_context_data(self,
|
||||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
"""Add current :class:`PersonAnswerSet` to context."""
|
"""Add current :class:`PersonAnswerSet` to context."""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
context['answer_set'] = self.object.current_answers
|
answer_set = self.object.current_answers
|
||||||
|
context['answer_set'] = answer_set
|
||||||
|
context['question_answers'] = self.build_question_answers(answer_set)
|
||||||
context['map_markers'] = [get_map_data(self.object)]
|
context['map_markers'] = [get_map_data(self.object)]
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|||||||
Reference in New Issue
Block a user