# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2016-12-21 17:20
from __future__ import unicode_literals

from django.db import migrations, models

import pretix.base.models.orders


def invalidate_ticket_cache(apps, schema_editor):
    CachedTicket = apps.get_model('pretixbase', 'CachedTicket')
    for ct in CachedTicket.objects.all():
        try:
            if ct.cachedfile:
                ct.cachedfile.delete()
                if ct.cachedfile.file:
                    ct.cachedfile.file.delete(False)
        except models.Model.DoesNotExist:
            pass
        ct.delete()


class Migration(migrations.Migration):

    dependencies = [
        ('pretixbase', '0050_orderposition_positionid'),
    ]

    operations = [
        migrations.RunPython(
            invalidate_ticket_cache, migrations.RunPython.noop
        ),
        migrations.RemoveField(
            model_name='cachedticket',
            name='cachedfile',
        ),
        migrations.AddField(
            model_name='cachedticket',
            name='extension',
            field=models.CharField(default='', max_length=255),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='cachedticket',
            name='file',
            field=models.FileField(blank=True, null=True, upload_to=pretix.base.models.orders.cachedticket_name),
        ),
        migrations.AddField(
            model_name='cachedticket',
            name='type',
            field=models.CharField(default='', max_length=255),
            preserve_default=False,
        ),
    ]
