Added a data migration to add author information to existing reviews.
- Legacy-Id: 12960
This commit is contained in:
parent
2f3fc88c82
commit
119f48699c
38
ietf/review/migrations/0011_auto_20170303_1009.py
Normal file
38
ietf/review/migrations/0011_auto_20170303_1009.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-03-03 10:09
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
def email(person):
|
||||
e = person.email_set.filter(primary=True).first()
|
||||
if not e:
|
||||
e = person.email_set.filter(active=True).order_by("-time").first()
|
||||
return e
|
||||
|
||||
def forwards(apps, schema_editor):
|
||||
ReviewRequest = apps.get_model('review', 'ReviewRequest')
|
||||
DocumentAuthor = apps.get_model('doc', 'DocumentAuthor')
|
||||
for r in ReviewRequest.objects.filter(review__isnull=False):
|
||||
if r.review and not r.review.authors.exists():
|
||||
role = r.reviewer.person.role_set.filter(group=r.team, name='reviewer').first()
|
||||
if role:
|
||||
author = role.email
|
||||
else:
|
||||
author = email(r.reviewer.person)
|
||||
DocumentAuthor.objects.create(document=r.review, author=author)
|
||||
|
||||
def backwards(apps, schema_editor):
|
||||
pass
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('review', '0010_auto_20161214_1537'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forwards, backwards)
|
||||
]
|
Loading…
Reference in a new issue