# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-14 11:01
from __future__ import unicode_literals

from django.db import migrations
from django.db.models import F


def set_suggestion_submitters(apps, schema_editor):
    subs = apps.get_model("pootle_statistics.Submission").objects
    accepted_subs = subs.filter(suggestion__state__name="accepted").values_list(
        "pk", "suggestion__user_id")
    for pk, user in accepted_subs.iterator():
        subs.filter(pk=pk).update(submitter_id=user)


class Migration(migrations.Migration):

    dependencies = [
        ('pootle_statistics', '0021_remove_paid_rates'),
    ]

    operations = [
        migrations.RunPython(set_suggestion_submitters),
    ]
