Skip to content

Commit

Permalink
[#3086] Ensure defaults for ContactFormSubject klant configs
Browse files Browse the repository at this point in the history
    - We check in the ContactFormSubject form that both esuite_config
      and openklant_config are set. By default, the first instances
      of ESuiteKlantConfig and OpenKlant2Config are assigned.
  • Loading branch information
pi-sigma authored and Paul Schilling committed Mar 5, 2025
1 parent a5c84a3 commit 6e7bafd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/open_inwoner/openklant/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def __init__(self, *args, **kwargs):
"Must be configured if E-suite is used"
)

# set defaults for klant configs if they're missing
if not self._meta.model.esuite_config:
self._meta.model.esuite_config = (
self._meta.model.esuite_config.field.related_model.objects.first()
)
if not self._meta.model.openklant_config:
self._meta.model.openklant_config = (
self._meta.model.openklant_config.field.related_model.objects.first()
)

class Meta:
model = ContactFormSubject
fields = (
Expand Down
4 changes: 1 addition & 3 deletions src/open_inwoner/openklant/tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def test_set_default_config(self):
OpenKlant2Config = self.apps.get_model("openklant", "OpenKlant2Config")

for contact_form_subject in ContactFormSubject.objects.all():
self.assertEqual(
contact_form_subject.esuite_config, self.esuite_config_1
)
self.assertEqual(contact_form_subject.esuite_config, self.esuite_config_1)
self.assertEqual(
contact_form_subject.openklant_config, self.openklant_config_1
)

0 comments on commit 6e7bafd

Please sign in to comment.