From e6fefd8c5212e9bf3c60a02acff7f1430787d310 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Tue, 6 Jun 2017 10:36:02 +0200 Subject: [PATCH] Add migration report.status mapping --- .../migrations/0044_auto_20170602_1836.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/submissions/migrations/0044_auto_20170602_1836.py b/submissions/migrations/0044_auto_20170602_1836.py index 472d624fc..329d7db77 100644 --- a/submissions/migrations/0044_auto_20170602_1836.py +++ b/submissions/migrations/0044_auto_20170602_1836.py @@ -5,6 +5,43 @@ from __future__ import unicode_literals from django.db import migrations, models +status_map_to_new = { + '1': 'vetted', + '0': 'unvetted', + '-1': 'unclear', + '-2': 'incorrect', + '-3': 'notuseful', + '-4': 'notacademic' +} +status_map_to_old = dict((v, int(k)) for k, v in status_map_to_new.items()) + + +def map_reports_to_new_status_codes(apps, schema_editor): + Report = apps.get_model('submissions', 'Report') + reports = Report.objects.all() + for report in reports: + try: + new_status = status_map_to_new[report.status] + except KeyError: + new_status = 'unvetted' + report.status = new_status + report.save() + print('\nUpdated %i reports.' % len(reports)) + + +def map_reports_to_old_status_codes(apps, schema_editor): + Report = apps.get_model('submissions', 'Report') + reports = Report.objects.all() + for report in reports: + try: + new_status = status_map_to_old[report.status] + except KeyError: + new_status = 0 + report.status = new_status + report.save() + print('\nUpdated %i reports.' % len(reports)) + + class Migration(migrations.Migration): dependencies = [ @@ -17,4 +54,5 @@ class Migration(migrations.Migration): name='status', field=models.CharField(choices=[('vetted', 'Vetted'), ('unvetted', 'Unvetted'), ('incorrect', 'Rejected (incorrect)'), ('unclear', 'Rejected (unclear)'), ('notuseful', 'Rejected (not useful)'), ('notacademic', 'Rejected (not academic in style)')], default='unvetted', max_length=16), ), + migrations.RunPython(map_reports_to_new_status_codes, map_reports_to_old_status_codes), ] -- GitLab