# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-09-14 23:44
#
# Goes through and moves some of the easiest stuff off the piles
#
#
##########################################################################
from __future__ import unicode_literals

from django.db import migrations

PAGES_GET_RID_OF = [19710, 19221, 19716]
PAGES_MARK_NEED_EVALUATION = [10811, 8155, 11328, 9572, 15045, 4747, 19966, 12713, 10868, 4745, 6146, 6579, 19212, 10883]


def do_stuff(apps, schemd_editor) -> None:
    Characters = apps.get_model('calligraphy', 'Character').objects
    PagesHaveChars = apps.get_model('calligraphy', 'PagesHaveChars').objects
    Pages = apps.get_model('calligraphy', 'Page').objects
    DetectedBox = apps.get_model('calligraphy', 'DetectedBox').objects
    ToDrawBoxesWBoxes = apps.get_model('calligraphy', 'ToDrawBoxesWBoxes')
    ToDrawBoxesWoBoxes = apps.get_model('calligraphy', 'ToDrawBoxesWoBoxes')
    
    #Move page back to the no-chars pile
    ToDrawBoxesWBoxes.objects.get(id=4974).delete()
    ToDrawBoxesWoBoxes(toCheck=Pages.get(id=1702)).save()
    
    for page_num in PAGES_GET_RID_OF:
        page = Pages.get(id=page_num)
        for char in Characters.filter(parent_page=page):
            char.delete()
        for h_char in PagesHaveChars.filter(haveChars=page):
            h_char.delete()
        for box in DetectedBox.filter(parent_page=page):
            box.delete()
        ToDrawBoxesWoBoxes(toCheck=page).save()
    
    for page_num in PAGES_MARK_NEED_EVALUATION:
        page = Pages.get(id=page_num)
        for box in DetectedBox.filter(parent_page=page):
            box.delete()
        ToDrawBoxesWBoxes(toCheck=page).save()
        
    
    

class Migration(migrations.Migration):

    dependencies = [
        ('calligraphy', '0120_auto_20170914_2251'),
    ]

    operations = [ migrations.RunPython(do_stuff)
    ]
