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

from django.db import models, migrations

QT_COMPETENCE = 0

def change_chars_to_digits_in_competence_questions_answers(apps, schema_editor):
    QuizzQuestionAnswer = apps.get_model('quizz', 'QuizzQuestionAnswer')
    competence_answers = QuizzQuestionAnswer.objects.filter(question__question_type=QT_COMPETENCE)
    competence_answers.filter(text='A').update(text='1')
    competence_answers.filter(text='B').update(text='2')
    competence_answers.filter(text='C').update(text='3')
    competence_answers.filter(text='D').update(text='4')
    competence_answers.filter(text='E').update(text='5')

def change_digits_to_chars_in_competence_questions_answers(apps, schema_editor):
    QuizzQuestionAnswer = apps.get_model('quizz', 'QuizzQuestionAnswer')
    competence_answers = QuizzQuestionAnswer.objects.filter(question__question_type=QT_COMPETENCE)
    competence_answers.filter(text='1').update(text='A')
    competence_answers.filter(text='2').update(text='B')
    competence_answers.filter(text='3').update(text='C')
    competence_answers.filter(text='4').update(text='D')
    competence_answers.filter(text='5').update(text='E')


class Migration(migrations.Migration):

    dependencies = [
        ('quizz', '0006_merge'),
    ]

    operations = [
        migrations.RunPython(change_chars_to_digits_in_competence_questions_answers,
                             change_digits_to_chars_in_competence_questions_answers)
    ]
