feat: specify whether question answers are public

Resolves #62
This commit is contained in:
James Graham
2021-02-08 14:42:07 +00:00
parent 9164ea8a05
commit a141b93644
3 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2021-02-08 13:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('people', '0031_question_allow_free_text'),
]
operations = [
migrations.AddField(
model_name='personquestion',
name='answer_is_public',
field=models.BooleanField(default=True, help_text='Should answers to this question be displayed on profiles?'),
),
]

View File

@@ -95,6 +95,12 @@ class Theme(models.Model):
class PersonQuestion(Question):
"""Question which may be asked about a person."""
#: Should answers to this question be displayed on public profiles?
answer_is_public = models.BooleanField(
help_text='Should answers to this question be displayed on profiles?',
default=True,
blank=False,
null=False)
class PersonQuestionChoice(QuestionChoice):
@@ -193,6 +199,10 @@ class PersonAnswerSet(AnswerSet):
#: Longitude for displaying location on a map
longitude = models.FloatField(blank=True, null=True)
def public_answers(self) -> models.QuerySet:
"""Get answers to questions which are public."""
return self.question_answers.filter(question__answer_is_public=True)
def as_dict(self):
"""Get the answers from this set as a dictionary for use in Form.initial."""
exclude_fields = {

View File

@@ -15,7 +15,7 @@
<tr><td>Organisation</td><td>{{ answer_set.organisation }}</td></tr>
{% endif %}
{% for answer in answer_set.question_answers.all %}
{% for answer in answer_set.public_answers.all %}
<tr>
<td>{{ answer.question }}</td>
<td>{{ answer }}</td>