diff --git a/people/forms.py b/people/forms.py index 706034b..0423431 100644 --- a/people/forms.py +++ b/people/forms.py @@ -164,6 +164,8 @@ class PersonAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase): 'organisation_started_date', 'project_started_date', 'job_title', + 'disciplinary_background', + 'external_organisations', 'latitude', 'longitude', ] @@ -178,6 +180,8 @@ class PersonAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase): labels = { 'project_started_date': f'Date started on the {settings.PARENT_PROJECT_NAME} project', + 'external_organisations': + 'Please list the main organisations external to BRECcIA work that you have been working with since 1st January 2019 that are involved in food/water security in African dryland regions' } help_texts = { 'organisation_started_date': diff --git a/people/migrations/0048_disciplines_and_organisations.py b/people/migrations/0048_disciplines_and_organisations.py new file mode 100644 index 0000000..a904a9c --- /dev/null +++ b/people/migrations/0048_disciplines_and_organisations.py @@ -0,0 +1,67 @@ +# Generated by Django 2.2.10 on 2021-03-16 08:14 + +from django.core.exceptions import ObjectDoesNotExist +from django.db import migrations, models + + +def forward_disciplines(apps, schema_editor): + PersonQuestion = apps.get_model('people', 'PersonQuestion') + + try: + question = PersonQuestion.objects.filter( + text='Disciplinary background').latest('version') + + PersonAnswerSet = apps.get_model('people', 'PersonAnswerSet') + for answerset in PersonAnswerSet.objects.all(): + answerset.disciplinary_background = ', '.join( + answerset.question_answers.filter(question=question).values_list( + 'text', flat=True)) + answerset.save() + + question.delete() + + except ObjectDoesNotExist: + pass + + +def forward_organisations(apps, schema_editor): + PersonQuestion = apps.get_model('people', 'PersonQuestion') + + try: + question = PersonQuestion.objects.filter( + text='Please list the main organisations external to BRECcIA work that you have been working with since 1st January 2019 that are involved in food/water security in African dryland regions' + ).latest('version') + + PersonAnswerSet = apps.get_model('people', 'PersonAnswerSet') + for answerset in PersonAnswerSet.objects.all(): + answerset.external_organisations = ', '.join( + answerset.question_answers.filter(question=question).values_list( + 'text', flat=True)) + answerset.save() + + question.delete() + + except ObjectDoesNotExist: + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0047_remove_personanswerset_external_organisations'), + ] + + operations = [ + migrations.AddField( + model_name='personanswerset', + name='disciplinary_background', + field=models.CharField(blank=True, help_text='Research discipline(s) you feel most affiliated with', max_length=255), + ), + migrations.RunPython(forward_disciplines), + migrations.AddField( + model_name='personanswerset', + name='external_organisations', + field=models.CharField(blank=True, max_length=1023), + ), + migrations.RunPython(forward_organisations), + ] diff --git a/people/models/person.py b/people/models/person.py index 452b226..b1bf9c7 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -169,6 +169,17 @@ class PersonAnswerSet(AnswerSet): blank=True, null=False) + disciplinary_background = models.CharField( + help_text='Research discipline(s) you feel most affiliated with', + max_length=255, + blank=True, + null=False) + + #: Organisations worked with which aren't in the Organisations list + external_organisations = models.CharField(max_length=1023, + blank=True, + null=False) + #: Latitude for displaying location on a map latitude = models.FloatField(blank=True, null=True) @@ -203,7 +214,8 @@ class PersonAnswerSet(AnswerSet): answers = { # Foreign key fields have _id at end in model _meta but don't in forms - field.attname.rstrip('_id'): field_value_repr(field) + # str.rstrip strips a set of characters, not a suffix, so doesn't work here + field.attname.rsplit('_id')[0]: field_value_repr(field) for field in self._meta.get_fields() if field.attname not in exclude_fields } diff --git a/people/templates/people/person/includes/answer_set_full.html b/people/templates/people/person/includes/answer_set_full.html index ca3343d..1b747c7 100644 --- a/people/templates/people/person/includes/answer_set_full.html +++ b/people/templates/people/person/includes/answer_set_full.html @@ -31,6 +31,14 @@