mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
refactor: allow admin config of static questions
Text and visibility set in admin panel are now respected everywhere
This commit is contained in:
81
people/migrations/0051_refactor_hardcoded_questions.py
Normal file
81
people/migrations/0051_refactor_hardcoded_questions.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# Generated by Django 2.2.10 on 2021-03-19 14:37
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db.models import F
|
||||
|
||||
|
||||
def forward(apps, schema_editor):
|
||||
"""Move `text` field to `hardcoded_field`."""
|
||||
models = [
|
||||
'OrganisationQuestion',
|
||||
'OrganisationRelationshipQuestion',
|
||||
'PersonQuestion',
|
||||
'RelationshipQuestion',
|
||||
]
|
||||
models = map(lambda m: apps.get_model('people', m), models)
|
||||
|
||||
for model in models:
|
||||
model.objects.filter(is_hardcoded=True).update(
|
||||
hardcoded_field=F('text'))
|
||||
|
||||
|
||||
def backward(apps, schema_editor):
|
||||
"""Move `hardcoded_field` to `text` field."""
|
||||
models = [
|
||||
'OrganisationQuestion',
|
||||
'OrganisationRelationshipQuestion',
|
||||
'PersonQuestion',
|
||||
'RelationshipQuestion',
|
||||
]
|
||||
models = map(lambda m: apps.get_model('people', m), models)
|
||||
|
||||
for model in models:
|
||||
model.objects.exclude(hardcoded_field='').update(
|
||||
text=F('hardcoded_field'), is_hardcoded=True)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0050_relationship_remove_timestamps'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='organisationquestion',
|
||||
name='hardcoded_field',
|
||||
field=models.CharField(blank=True, help_text='Which hardcoded field does this question represent?', max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='organisationrelationshipquestion',
|
||||
name='hardcoded_field',
|
||||
field=models.CharField(blank=True, help_text='Which hardcoded field does this question represent?', max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='personquestion',
|
||||
name='hardcoded_field',
|
||||
field=models.CharField(blank=True, help_text='Which hardcoded field does this question represent?', max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='relationshipquestion',
|
||||
name='hardcoded_field',
|
||||
field=models.CharField(blank=True, help_text='Which hardcoded field does this question represent?', max_length=255),
|
||||
),
|
||||
migrations.RunPython(forward, backward),
|
||||
migrations.RemoveField(
|
||||
model_name='organisationquestion',
|
||||
name='is_hardcoded',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='organisationrelationshipquestion',
|
||||
name='is_hardcoded',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='personquestion',
|
||||
name='is_hardcoded',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='relationshipquestion',
|
||||
name='is_hardcoded',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user