# Generated by Django 3.2.20 on 2023-09-25 14:48

from django.db import migrations, models


def set_url_expert_course_session_assignments(apps):
    # need to load concrete model, so that wagtail page has `specific` instance  method...
    from vbv_lernwelt.course_session.models import CourseSessionAssignment

    for assignment in CourseSessionAssignment.objects.all():
        # trigger save to update due_date foreign key fields
        assignment.save()


def set_url_expert_course_session_edoniq_test(apps):
    # need to load concrete model, so that wagtail page has `specific` instance  method...
    from vbv_lernwelt.course_session.models import CourseSessionEdoniqTest

    for edoniq_test in CourseSessionEdoniqTest.objects.all():
        # trigger save to update due_date foreign key fields
        edoniq_test.save()


def set_url_expert_course_session_attendances(apps):
    # need to load concrete model, so that wagtail page has `specific` instance  method...
    from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse

    for attendance in CourseSessionAttendanceCourse.objects.all():
        # trigger save to update due_date foreign key fields
        attendance.save()


def set_url_expert_default(apps, schema_editor):
    set_url_expert_course_session_assignments(apps)
    set_url_expert_course_session_attendances(apps)
    set_url_expert_course_session_edoniq_test(apps)


def reverse_func(apps, schema_editor):
    # so we can reverse this migration, but noop
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("duedate", "0004_alter_duedate_start"),
        ("learnpath", "0008_add_edoniq_sequence_id"),
        ("course_session", "0005_auto_20230825_1723"),
    ]

    operations = [
        migrations.AddField(
            model_name="duedate",
            name="url_expert",
            field=models.CharField(
                blank=True,
                default="",
                help_text="URL wird aus dem LearningContent generiert (sichtbar für den Experten/Trainer)",
                max_length=1024,
            ),
        ),
        migrations.AlterField(
            model_name="duedate",
            name="url",
            field=models.CharField(
                blank=True,
                default="",
                help_text="URL wird vom LearningContent übernommen (sichtbar für Member/Teilnehmer)",
                max_length=1024,
            ),
        ),
        migrations.RunPython(set_url_expert_default, reverse_func),
    ]
