fix: error when viewing profile with no answerset

This commit is contained in:
James Graham
2021-03-10 15:03:24 +00:00
parent 667a51d1c7
commit 3ad8d4a5c9
5 changed files with 34 additions and 6 deletions

View File

@@ -62,6 +62,12 @@
<td>{{ answers }}</td> <td>{{ answers }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody> </tbody>
</table> </table>

View File

@@ -37,6 +37,12 @@
<td>{{ answers }}</td> <td>{{ answers }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody> </tbody>
</table> </table>

View File

@@ -21,6 +21,12 @@
<td>{{ answers }}</td> <td>{{ answers }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if answer_set is None %}
<tr>
<td colspan="2">No answers</td>
</tr>
{% endif %}
</tbody> </tbody>
</table> </table>

View File

@@ -114,10 +114,15 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
questions = questions.filter(answer_is_public=True) questions = questions.filter(answer_is_public=True)
question_answers = {} question_answers = {}
try:
for question in questions: 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))
except AttributeError:
# No AnswerSet yet
pass
return question_answers return question_answers
def get_context_data(self, def get_context_data(self,

View File

@@ -79,10 +79,15 @@ class ProfileView(LoginRequiredMixin, DetailView):
questions = questions.filter(answer_is_public=True) questions = questions.filter(answer_is_public=True)
question_answers = {} question_answers = {}
try:
for question in questions: 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))
except AttributeError:
# No AnswerSet yet
pass
return question_answers return question_answers
def get_context_data(self, def get_context_data(self,