# Generated by Django 2.1.8 on 2019-06-06 13:18

import os
from django.db import migrations
from django.core.files import File
from django.conf import settings


def upload_geo_files(apps, schema_editor):
    GeoArea = apps.get_model('geo', 'GeoArea')

    for geoarea in GeoArea.objects.all():
        filename = geoarea.file.name
        filepath = os.path.join(settings.BASE_DIR, filename)
        with open(filepath, 'rb') as fp:
            geoarea.file = File(fp, filename.split('/')[-1])
            geoarea.save()


class Migration(migrations.Migration):

    dependencies = [
        ('geo', '0005_update_geostyles_20190606_1302'),
    ]

    operations = [
        migrations.AlterUniqueTogether(
            name='geostylefile',
            unique_together={('language', 'geo_style')},
        ),
        migrations.RunPython(upload_geo_files),
    ]
