# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-30 16:08
from __future__ import unicode_literals

from django.db import migrations, models


def set_source(apps, schema_editor):
    Source = apps.get_model('contributions', 'Source')
    Contribution = apps.get_model('contributions', 'Contribution')
    BulkPayment = apps.get_model('contributions', 'BulkPayment')
    Pledge = apps.get_model('contributions', 'Pledge')

    sources = {}
    for source in Source.objects.all():
        sources[source.name] = source

    for obj in BulkPayment.objects.all().iterator():
        if obj.source_old:
            obj.source = sources[obj.get_source_old_display()]
        obj.save()

    for obj in Contribution.objects.all().iterator():
        if obj.source_old:
            obj.source = sources[obj.get_source_old_display()]
        obj.save()

    for obj in Pledge.objects.all().iterator():
        if obj.source_old:
            obj.source = sources[obj.get_source_old_display()]
        obj.save()


class Migration(migrations.Migration):

    dependencies = [
        ('contributions', '0064_auto_20170330_1608'),
    ]

    operations = [
        migrations.RunPython(set_source),
    ]
