SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e6fefd8c authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Add migration report.status mapping

parent ff0cd9b5
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,43 @@ from __future__ import unicode_literals ...@@ -5,6 +5,43 @@ from __future__ import unicode_literals
from django.db import migrations, models 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): class Migration(migrations.Migration):
dependencies = [ dependencies = [
...@@ -17,4 +54,5 @@ class Migration(migrations.Migration): ...@@ -17,4 +54,5 @@ class Migration(migrations.Migration):
name='status', 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), 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),
] ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment