mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
@@ -15,7 +15,7 @@ class OrganisationForm(forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = models.Organisation
|
model = models.Organisation
|
||||||
fields = [
|
fields = [
|
||||||
'name'
|
'name',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -41,12 +41,15 @@ class DynamicAnswerSetBase(forms.Form):
|
|||||||
question_model: typing.Type[models.Question]
|
question_model: typing.Type[models.Question]
|
||||||
answer_model: typing.Type[models.QuestionChoice]
|
answer_model: typing.Type[models.QuestionChoice]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, as_filters: bool = False, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
initial = kwargs.get('initial', {})
|
initial = kwargs.get('initial', {})
|
||||||
|
|
||||||
for question in self.question_model.objects.all():
|
for question in self.question_model.objects.all():
|
||||||
|
if as_filters and not question.answer_is_public:
|
||||||
|
continue
|
||||||
|
|
||||||
field_class = self.field_class
|
field_class = self.field_class
|
||||||
field_widget = self.field_widget
|
field_widget = self.field_widget
|
||||||
|
|
||||||
@@ -56,10 +59,16 @@ class DynamicAnswerSetBase(forms.Form):
|
|||||||
|
|
||||||
field_name = f'question_{question.pk}'
|
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,
|
queryset=question.answers,
|
||||||
widget=field_widget,
|
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))
|
initial=initial.get(field_name, None))
|
||||||
self.fields[field_name] = field
|
self.fields[field_name] = field
|
||||||
|
|
||||||
@@ -235,7 +244,7 @@ class NetworkFilterForm(DynamicAnswerSetBase):
|
|||||||
answer_model = models.RelationshipQuestionChoice
|
answer_model = models.RelationshipQuestionChoice
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
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
|
# Add date field to select relationships at a particular point in time
|
||||||
self.fields['date'] = forms.DateField(
|
self.fields['date'] = forms.DateField(
|
||||||
|
|||||||
33
people/migrations/0037_alternate_filter_text.py
Normal file
33
people/migrations/0037_alternate_filter_text.py
Normal file
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -186,12 +186,6 @@ class Theme(models.Model):
|
|||||||
|
|
||||||
class PersonQuestion(Question):
|
class PersonQuestion(Question):
|
||||||
"""Question which may be asked about a person."""
|
"""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):
|
class PersonQuestionChoice(QuestionChoice):
|
||||||
|
|||||||
@@ -24,9 +24,23 @@ class Question(models.Model):
|
|||||||
blank=False,
|
blank=False,
|
||||||
null=False)
|
null=False)
|
||||||
|
|
||||||
#: Text of question
|
#: Text of question - 1st person
|
||||||
text = models.CharField(max_length=255, blank=False, null=False)
|
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?
|
#: Should people be able to select multiple responses to this question?
|
||||||
is_multiple_choice = models.BooleanField(default=False,
|
is_multiple_choice = models.BooleanField(default=False,
|
||||||
blank=False,
|
blank=False,
|
||||||
|
|||||||
Reference in New Issue
Block a user