# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-08 19:29
#
# Goes through and moves black-chars from box to page
#
############################################################################
from __future__ import unicode_literals

from django.db import migrations

def do_stuff(apps, schemd_editor):
    pages_web = apps.get_model('calligraphy', 'Page').objects.filter(has_copyright_restrictions=False)
    DetectedBox = apps.get_model('calligraphy', 'DetectedBox').objects
    for page in pages_web:
        detected_boxes = DetectedBox.filter(parent_page=page)
        if len(detected_boxes) > 0:
            page.black_chars = detected_boxes[0].black_chars
            page.save()

class Migration(migrations.Migration):

    dependencies = [
        ('calligraphy', '0226_page_black_chars'),
    ]

    operations = [ migrations.RunPython(do_stuff)
    ]
