# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os

from django.conf import settings
from django.db import migrations

PHOTOSTORY_PATH = os.path.join(settings.MEDIA_ROOT, 'upload/photostory')

def forwards_func(apps, schema_editor):
    """Import photostory from their old directory """

    Photostory = apps.get_model(
        "photostories",
        "Photostory"
    )
    if os.path.exists(PHOTOSTORY_PATH) and os.path.isdir(PHOTOSTORY_PATH):
        Photostory.objects.import_photostory_from(PHOTOSTORY_PATH)


def backward_func(apps, schema_editor):
    """Export photostory to their old directory """

    Photostory = apps.get_model(
        "photostories",
        "Photostory"
    )
    Photostory.objects.export_photostory_to(PHOTOSTORY_PATH)


class Migration(migrations.Migration):
    dependencies = [
        ('photostories', '0002_change_manager_for_photostory'),
        ('trainings', '0044_training_activity_nullable_training_field')
    ]

    operations = [
        migrations.RunPython(forwards_func, backward_func),
    ]
