# Generated by Django 2.2b1 on 2019-03-09 14:27

from django.db import migrations, models
import imagekit.models.fields
import openbook_posts.helpers


def create_post_image_width_and_height(apps, schema_editor):
    PostImage = apps.get_model('openbook_posts', 'PostImage')
    for post_image in PostImage.objects.all():
        try:
            file = post_image.image.file
            post_image.width = post_image.image.width
            post_image.height = post_image.image.height
        except FileNotFoundError:
            post_image.width = 100
            post_image.height = 100

        post_image.save()


class Migration(migrations.Migration):
    dependencies = [
        ('openbook_posts', '0019_postmute'),
    ]

    operations = [
        migrations.AddField(
            model_name='postimage',
            name='height',
            field=models.PositiveIntegerField(editable=False, null=True),
        ),
        migrations.AddField(
            model_name='postimage',
            name='width',
            field=models.PositiveIntegerField(editable=False, null=True),
        ),
        migrations.RunPython(create_post_image_width_and_height),
        migrations.AlterField(
            model_name='postimage',
            name='image',
            field=imagekit.models.fields.ProcessedImageField(null=True,
                                                             upload_to=openbook_posts.helpers.upload_to_post_image_directory,
                                                             verbose_name='image'),
        ),
        migrations.AlterField(
            model_name='postvideo',
            name='video',
            field=models.FileField(upload_to=openbook_posts.helpers.upload_to_post_video_directory,
                                   verbose_name='video'),
        ),
    ]
