# Generated by Django 3.2.19 on 2023-08-02 19:49

from django.db import migrations, models

from NEMO.apps.nemo_ce.migration_utils import NEMOMigration


class Migration(NEMOMigration):

    dependencies = [
        ("NEMO", "0048_version_4_6_3"),
        ("nemo_ce", "0008_ce_qualification_level_in_training_history"),
    ]

    def rename_customization(apps, schema_editor):
        Customization = apps.get_model("NEMO", "Customization")
        try:
            grant_access_emails_old = Customization.objects.get(name="tool_grant_badge_access_emails")
            Customization.objects.create(name="tool_grant_access_emails", value=grant_access_emails_old.value)
            grant_access_emails_old.delete()
        except:
            pass

    operations = [
        migrations.RunPython(rename_customization),
        migrations.AddField(
            model_name="tool",
            name="_grant_access_for_qualification_levels",
            field=models.ManyToManyField(
                blank=True,
                help_text="Granting physical access or badge reader access will only apply to the selected qualification levels. If left empty it will apply to all qualification levels.",
                to="NEMO.QualificationLevel",
            ),
        ),
    ]
