# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2021-06-02 08:17
from __future__ import unicode_literals

from django.db import migrations


def copy_handshape_values(apps, schema_editor):
    MissingSignFeedback = apps.get_model('feedback', 'MissingSignFeedback')
    Handshape = apps.get_model('dictionary', 'Handshape')

    # Put all handshapes in a dict for convenient lookup
    handshapes = dict([(handshape.machine_value, handshape) for handshape in Handshape.objects.all()])

    # Copy values for each Gloss
    for missingsignfeedback in MissingSignFeedback.objects.all():
        if missingsignfeedback.handshape_fk:
            missingsignfeedback.handshape_handshapefk = handshapes[missingsignfeedback.handshape_fk.machine_value]
        if missingsignfeedback.althandshape_fk:
            missingsignfeedback.althandshape_handshapefk = handshapes[missingsignfeedback.althandshape_fk.machine_value]
        missingsignfeedback.save()


class Migration(migrations.Migration):

    dependencies = [
        ('feedback', '0006_auto_20210602_1006'),
    ]

    operations = [
        migrations.RunPython(copy_handshape_values),
    ]
