refactor: move disciplines and orgs to free text

Resolves #102
This commit is contained in:
James Graham
2021-03-16 11:54:34 +00:00
parent 583a49fdd3
commit 98e9148998
4 changed files with 92 additions and 1 deletions

View File

@@ -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':

View File

@@ -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),
]

View File

@@ -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
}

View File

@@ -31,6 +31,14 @@
<tr><td>Job Title</td><td>{{ answer_set.job_title }}</td></tr>
{% endif %}
{% if answer_set.disciplinary_background %}
<tr><td>Disciplinary Background</td><td>{{ answer_set.disciplinary_background }}</td></tr>
{% endif %}
{% if answer_set.external_organisations %}
<tr><td>External Organisations Worked With</td><td>{{ answer_set.external_organisations }}</td></tr>
{% endif %}
{% for question, answers in question_answers.items %}
<tr>
<td>{{ question }}</td>