# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-12-01 11:19
from __future__ import unicode_literals

from django.db import migrations


def populate_slide_evaluations(apps, schema_editor):
    SlideEvaluation = apps.get_model('slides_manager', 'SlideEvaluation')
    SlideQualityControl = apps.get_model('slides_manager', 'SlideQualityControl')

    for qc in SlideQualityControl.objects.all():
        SlideEvaluation(
            slide=qc.slide, rois_annotation_step=qc.rois_annotation_step,
            staining=qc.slide.staining, adequate_slide=qc.adequate_slide,
            not_adequacy_reason=qc.not_adequacy_reason, notes=qc.notes,
            reviewer=qc.reviewer, acquisition_date=qc.acquisition_date
        ).save()


def clear_slide_evaluations(apps, schema_editor):
    SlideEvaluation = apps.get_model('slides_manager', 'SlideEvaluation')

    for se in SlideEvaluation.objects.all():
        se.delete()


class Migration(migrations.Migration):

    dependencies = [
        ('slides_manager', '0013_slideevaluation'),
    ]

    operations = [
        migrations.RunPython(populate_slide_evaluations, clear_slide_evaluations)
    ]

build SlideEvaluation objects from existing data