diff --git a/people/forms.py b/people/forms.py index 3f567b8..8551743 100644 --- a/people/forms.py +++ b/people/forms.py @@ -15,7 +15,7 @@ class OrganisationForm(forms.ModelForm): class Meta: model = models.Organisation fields = [ - 'name' + 'name', ] @@ -41,12 +41,15 @@ class DynamicAnswerSetBase(forms.Form): question_model: typing.Type[models.Question] answer_model: typing.Type[models.QuestionChoice] - def __init__(self, *args, **kwargs): + def __init__(self, *args, as_filters: bool = False, **kwargs): super().__init__(*args, **kwargs) initial = kwargs.get('initial', {}) for question in self.question_model.objects.all(): + if as_filters and not question.answer_is_public: + continue + field_class = self.field_class field_widget = self.field_widget @@ -56,10 +59,16 @@ class DynamicAnswerSetBase(forms.Form): field_name = f'question_{question.pk}' - field = field_class(label=question, + # If being used as a filter - do we have alternate text? + field_label = question.text + if as_filters and question.filter_text: + field_label = question.filter_text + + field = field_class(label=field_label, queryset=question.answers, widget=field_widget, - required=self.field_required and not question.allow_free_text, + required=(self.field_required + and not question.allow_free_text), initial=initial.get(field_name, None)) self.fields[field_name] = field @@ -235,7 +244,7 @@ class NetworkFilterForm(DynamicAnswerSetBase): answer_model = models.RelationshipQuestionChoice def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super().__init__(*args, as_filters=True, **kwargs) # Add date field to select relationships at a particular point in time self.fields['date'] = forms.DateField( diff --git a/people/migrations/0037_alternate_filter_text.py b/people/migrations/0037_alternate_filter_text.py new file mode 100644 index 0000000..4d2f7cf --- /dev/null +++ b/people/migrations/0037_alternate_filter_text.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.10 on 2021-03-01 18:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0036_move_latlng_to_answerset'), + ] + + operations = [ + migrations.AddField( + model_name='organisationquestion', + name='filter_text', + field=models.CharField(blank=True, help_text='Text to be displayed in network filters - 3rd person', max_length=255), + ), + migrations.AddField( + model_name='personquestion', + name='filter_text', + field=models.CharField(blank=True, help_text='Text to be displayed in network filters - 3rd person', max_length=255), + ), + migrations.AddField( + model_name='relationshipquestion', + name='answer_is_public', + field=models.BooleanField(default=True, help_text='Should answers to this question be considered public?'), + ), + migrations.AddField( + model_name='relationshipquestion', + name='filter_text', + field=models.CharField(blank=True, help_text='Text to be displayed in network filters - 3rd person', max_length=255), + ), + ] diff --git a/people/models/person.py b/people/models/person.py index e4459a4..2f110d5 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -186,12 +186,6 @@ 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): diff --git a/people/models/question.py b/people/models/question.py index 7948640..b5ccadf 100644 --- a/people/models/question.py +++ b/people/models/question.py @@ -24,9 +24,23 @@ class Question(models.Model): blank=False, null=False) - #: Text of question + #: Text of question - 1st person text = models.CharField(max_length=255, blank=False, null=False) + #: Text to be displayed in network filters - 3rd person + filter_text = models.CharField( + max_length=255, + blank=True, + null=False, + help_text='Text to be displayed in network filters - 3rd person') + + #: Should answers to this question be considered public? + answer_is_public = models.BooleanField( + help_text='Should answers to this question be considered public?', + default=True, + blank=False, + null=False) + #: Should people be able to select multiple responses to this question? is_multiple_choice = models.BooleanField(default=False, blank=False,