|
| 1 | +# Generated by Django 4.2.18 on 2025-03-04 13:08 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | +from django.db.models import Q |
| 5 | + |
| 6 | + |
| 7 | +def set_default_for_klant_config(apps, _): |
| 8 | + ContactFormSubject = apps.get_model("openklant", "ContactFormSubject") |
| 9 | + ESuiteKlantConfig = apps.get_model("openklant", "ESuiteKlantConfig") |
| 10 | + OpenKlant2Config = apps.get_model("openklant", "OpenKlant2Config") |
| 11 | + |
| 12 | + for contact_form_subject in ContactFormSubject.objects.filter( |
| 13 | + Q(esuite_config__isnull=True) | Q(openklant_config__isnull=True) |
| 14 | + ): |
| 15 | + contact_form_subject.esuite_config = ( |
| 16 | + contact_form_subject.esuite_config or ESuiteKlantConfig.objects.first() |
| 17 | + ) |
| 18 | + contact_form_subject.openklant_config = ( |
| 19 | + contact_form_subject.esuite_config or OpenKlant2Config.objects.first() |
| 20 | + ) |
| 21 | + contact_form_subject.save() |
| 22 | + |
| 23 | + |
| 24 | +def delete_default_for_klant_config(apps, _): |
| 25 | + ContactFormSubject = apps.get_model("openklant", "ContactFormSubject") |
| 26 | + |
| 27 | + for contact_form_subject in ContactFormSubject.objects.filter( |
| 28 | + Q(esuite_config__isnull=False) | Q(openklant_config__isnull=False) |
| 29 | + ): |
| 30 | + contact_form_subject.esuite_config = None |
| 31 | + contact_form_subject.openklant_config = None |
| 32 | + contact_form_subject.save() |
| 33 | + |
| 34 | + |
| 35 | +class Migration(migrations.Migration): |
| 36 | + |
| 37 | + dependencies = [ |
| 38 | + ("openklant", "0025_esuiteklantconfig_send_klantcontact_confirmation_email"), |
| 39 | + ] |
| 40 | + |
| 41 | + operations = [ |
| 42 | + migrations.RunPython( |
| 43 | + code=set_default_for_klant_config, |
| 44 | + reverse_code=delete_default_for_klant_config, |
| 45 | + ) |
| 46 | + ] |
0 commit comments