# Generated by Django 2.2.13 on 2021-07-07 11:51
import logging

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

LIMIT_START_YEAR = 2021
logger = logging.getLogger(settings.DEFAULT_LOGGER)


def set_stage_dimona_to_true_for_internship_type(apps, schema_editor):
    LearningUnitYear = apps.get_model('base', 'learningunityear')

    all_internships_to_update = LearningUnitYear.objects.filter(
        academic_year__year__gte=LIMIT_START_YEAR,
        learning_container_year__container_type='INTERNSHIP'
    ).update(
        stage_dimona=True
    )
    logger.info('Stage-Dimona field has been updated for {} Learning Unit Year'.format(all_internships_to_update))


class Migration(migrations.Migration):

    dependencies = [
        ('base', '0589_learningunityear_stage_dimona'),
    ]

    operations = [
        migrations.RunPython(set_stage_dimona_to_true_for_internship_type, elidable=True),
    ]
