# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-15 11:59
from __future__ import unicode_literals

from django.db import migrations
from django.utils import timezone


def set_removal_time_to_existing_output_files(apps, schema_editor):
    Export = apps.get_model("excerptexport", "Export")  # noqa
    for export in Export.objects.all():
        if hasattr(export, 'output_file'):
            output_file = export.output_file
            if not output_file.file_removal_at:
                output_file.file_removal_at = export.updated_at + timezone.timedelta(days=14)
                output_file.save()


def unset_removal_time_to_existing_output_files(apps, schema_editor):
    # no need to unset this, but reversing should be enabled.
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('excerptexport', '0048_outputfile_file_removal_at'),
    ]

    operations = [
        migrations.RunPython(set_removal_time_to_existing_output_files, unset_removal_time_to_existing_output_files)
    ]

add 14 days until removal for existing export files