Added a data migration to upgrade the submission checker json details to a consistent format.

- Legacy-Id: 14269
This commit is contained in:
Henrik Levkowetz 2017-11-01 14:45:25 +00:00
parent 1e98a58386
commit 48a81862b8

View file

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2017-10-27 06:34
from __future__ import unicode_literals
from django.db import migrations
# convert the SubmissionCheck.items to consistently be a dict, with the
# following content:
# {
# 'checker': <string>;
# 'message': <string>;
# 'items': <list>; # error or warning items
# 'draft': <draftname>;
# 'modules': { <extracted module info> },
# }
def forwards(apps, schema_editor):
SubmissionCheck = apps.get_model('submit', 'SubmissionCheck')
for check in SubmissionCheck.objects.all().order_by('id'):
# deal with these cases:
# * empty dictionary
# * empty list
# * dictionary with idnits info
# * list with yang errors and warnings
items = []
if check.items == {} or check.items == '{}':
pass
elif check.items == []:
pass
elif type(check.items) == dict:
if 'checker' in check.items:
continue
elif type(check.items) == list:
items = check.items
else:
raise ValueError("Unexpected check.items value: %s: %s" % (type(check.items), check.items))
check.items = {
'checker': check.checker,
'draft': check.submission.name,
'rev': check.submission.rev,
'items': items,
'code': {},
}
check.save()
def backwards(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('meeting', '0058_set_new_field_meeting_days_values'),
('submit', '0021_submissioncheck_time_default'),
]
operations = [
migrations.RunPython(forwards, backwards),
]