Skip to content

Commit 1e2e548

Browse files
authored
Merge pull request #1653 from maykinmedia/issue/3086-contactform_subject_configs
[#3086] Add defaults for ContactFormSubject klant configs
2 parents a2d9fdd + 4a8e818 commit 1e2e548

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from open_inwoner.utils.tests.test_migrations import TestSuccessfulMigrations
2+
3+
4+
class ContactFormSubjectConfigMigrationTest(TestSuccessfulMigrations):
5+
migrate_from = "0025_esuiteklantconfig_send_klantcontact_confirmation_email"
6+
migrate_to = "0026_contactform_subject_config_default"
7+
app = "openklant"
8+
9+
def setUpBeforeMigration(self, app):
10+
ContactFormSubject = app.get_model("openklant", "ContactFormSubject")
11+
ESuiteKlantConfig = app.get_model("openklant", "ESuiteKlantConfig")
12+
OpenKlant2Config = app.get_model("openklant", "OpenKlant2Config")
13+
14+
self.esuite_config_1 = ESuiteKlantConfig.objects.create()
15+
self.esuite_config_2 = ESuiteKlantConfig.objects.create()
16+
self.openklant_config_1 = OpenKlant2Config.objects.create()
17+
self.openklant_config_2 = OpenKlant2Config.objects.create()
18+
19+
for contact_form_subject in ContactFormSubject.objects.all():
20+
contact_form_subject.esuite_config = None
21+
contact_form_subject.openklant_config = None
22+
contact_form_subject.save()
23+
24+
def test_set_default_config(self):
25+
ContactFormSubject = self.apps.get_model("openklant", "ContactFormSubject")
26+
27+
for contact_form_subject in ContactFormSubject.objects.all():
28+
self.assertEqual(contact_form_subject.esuite_config, self.esuite_config_1)
29+
self.assertEqual(
30+
contact_form_subject.openklant_config, self.openklant_config_1
31+
)

0 commit comments

Comments
 (0)