# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-11-08 20:10
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion

def remove_compilejobs(apps, db_schema):
    CompileJob = apps.get_model("problems", "compilejob")
    CompileJob.objects.using(db_schema.connection.alias).delete()


def update_validator(apps, db_schema):
    Validator = apps.get_model("problems", "validator")
    objs = Validator.objects.using(db_schema.connection.alias).all()
    for obj in objs:
        obj.name = obj.code.name
        obj.source_file_id = obj.code.source_file_id
        obj.source_language = obj.code.source_language
        obj.save()


class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('file_repository', '0006_auto_20161108_2010'),
        ('problems', '0033_auto_20161031_1024'),
    ]

    operations = [
        migrations.RunPython(remove_compilejobs, remove_compilejobs),
        migrations.CreateModel(
            name='Verifier',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(blank=True, max_length=256, validators=[django.core.validators.RegexValidator(code='invalid_file_name', inverse_match=False, message='please enter a valid file name.', regex='^[a-zA-Z0-9_\\-](?:\\.|[a-zA-Z0-9_\\-])*$')], verbose_name='name')),
                ('source_language', models.CharField(choices=[('c++', 'c++')], max_length=200, null=True)),
                ('last_compile_log', models.TextField(verbose_name='last compile log')),
                ('_compiled_file', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='compiled file')),
                ('problem', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='problems.ProblemRevision', verbose_name='problem')),
                ('source_file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='source file')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.AlterUniqueTogether(
            name='sourcefile',
            unique_together=set([]),
        ),

        migrations.AddField(
            model_name='compilejob',
            name='content_type',
            field=models.ForeignKey(null=True, default=None, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='compilejob',
            name='object_id',
            field=models.PositiveIntegerField(null=True, default=None),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='validator',
            name='_compiled_file',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='compiled file'),
        ),
        migrations.AddField(
            model_name='validator',
            name='last_compile_log',
            field=models.TextField(default='', verbose_name='last compile log'),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='validator',
            name='name',
            field=models.CharField(blank=True, max_length=256, validators=[django.core.validators.RegexValidator(code='invalid_file_name', inverse_match=False, message='please enter a valid file name.', regex='^[a-zA-Z0-9_\\-](?:\\.|[a-zA-Z0-9_\\-])*$')], verbose_name='name'),
        ),
        migrations.AddField(
            model_name='validator',
            name='source_file',
            field=models.ForeignKey(null=True, default=None, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='source file'),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='validator',
            name='source_language',
            field=models.CharField(choices=[('c++', 'c++')], max_length=200, null=True),
        ),
        migrations.RunPython(update_validator),
        migrations.AlterField(
            model_name='validator',
            name='source_file',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='source file'),
        ),
        migrations.RemoveField(
            model_name='sourcefile',
            name='_compiled_file',
        ),
        migrations.RemoveField(
            model_name='sourcefile',
            name='problem',
        ),
        migrations.RemoveField(
            model_name='sourcefile',
            name='source_file',
        ),
        migrations.RemoveField(
            model_name='compilejob',
            name='source_file',
        ),
        migrations.RemoveField(
            model_name='testcase',
            name='_input_generator',
        ),
        migrations.AlterField(
            model_name='attachment',
            name='name',
            field=models.CharField(blank=True, max_length=256, validators=[django.core.validators.RegexValidator(code='invalid_file_name', inverse_match=False, message='please enter a valid file name.', regex='^[a-zA-Z0-9_\\-](?:\\.|[a-zA-Z0-9_\\-])*$')], verbose_name='name'),
        ),
        migrations.AlterField(
            model_name='problemdata',
            name='checker',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='problems.Verifier', verbose_name='checker'),
        ),
        migrations.AlterField(
            model_name='solution',
            name='code',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='file_repository.FileModel', verbose_name='code'),
        ),
        migrations.RemoveField(
            model_name='validator',
            name='code',
        ),
        migrations.AlterUniqueTogether(
            name='validator',
            unique_together=set([('problem', 'name')]),
        ),
        migrations.DeleteModel(
            name='SourceFile',
        ),
        migrations.AlterUniqueTogether(
            name='verifier',
            unique_together=set([('problem', 'name')]),
        ),
    ]
