|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Generated by Django 1.10.8 on 2017-10-27 06:34 |
| 3 | +from __future__ import unicode_literals |
| 4 | + |
| 5 | +from django.db import migrations |
| 6 | + |
| 7 | +# convert the SubmissionCheck.items to consistently be a dict, with the |
| 8 | +# following content: |
| 9 | +# { |
| 10 | +# 'checker': <string>; |
| 11 | +# 'message': <string>; |
| 12 | +# 'items': <list>; # error or warning items |
| 13 | +# 'draft': <draftname>; |
| 14 | +# 'modules': { <extracted module info> }, |
| 15 | +# } |
| 16 | + |
| 17 | + |
| 18 | +def forwards(apps, schema_editor): |
| 19 | + SubmissionCheck = apps.get_model('submit', 'SubmissionCheck') |
| 20 | + for check in SubmissionCheck.objects.all().order_by('id'): |
| 21 | + # deal with these cases: |
| 22 | + # * empty dictionary |
| 23 | + # * empty list |
| 24 | + # * dictionary with idnits info |
| 25 | + # * list with yang errors and warnings |
| 26 | + items = [] |
| 27 | + if check.items == {} or check.items == '{}': |
| 28 | + pass |
| 29 | + elif check.items == []: |
| 30 | + pass |
| 31 | + elif type(check.items) == dict: |
| 32 | + if 'checker' in check.items: |
| 33 | + continue |
| 34 | + elif type(check.items) == list: |
| 35 | + items = check.items |
| 36 | + else: |
| 37 | + raise ValueError("Unexpected check.items value: %s: %s" % (type(check.items), check.items)) |
| 38 | + check.items = { |
| 39 | + 'checker': check.checker, |
| 40 | + 'draft': check.submission.name, |
| 41 | + 'rev': check.submission.rev, |
| 42 | + 'items': items, |
| 43 | + 'code': {}, |
| 44 | + } |
| 45 | + check.save() |
| 46 | + |
| 47 | +def backwards(apps, schema_editor): |
| 48 | + pass |
| 49 | + |
| 50 | +class Migration(migrations.Migration): |
| 51 | + |
| 52 | + dependencies = [ |
| 53 | + ('meeting', '0058_set_new_field_meeting_days_values'), |
| 54 | + ('submit', '0021_submissioncheck_time_default'), |
| 55 | + ] |
| 56 | + |
| 57 | + operations = [ |
| 58 | + migrations.RunPython(forwards, backwards), |
| 59 | + ] |
0 commit comments