Skip to content

Commit

Permalink
♻️ [#1838] Store zaaktype URL on ZaakTypeConfig
Browse files Browse the repository at this point in the history
task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1838

this is necessary to avoid performance issues when implementing personalization of categories based on zaaktypen
  • Loading branch information
stevenbal committed Nov 14, 2023
1 parent fa7fdc5 commit 58a2138
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin):
"mark_as_not_notify_status_changes",
]
fields = [
"url",
"catalogus",
"identificatie",
"omschrijving",
Expand All @@ -255,6 +256,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin):
"description",
]
readonly_fields = [
"url",
"catalogus",
"identificatie",
"omschrijving",
Expand Down
18 changes: 18 additions & 0 deletions src/open_inwoner/openzaak/migrations/0031_zaaktypeconfig_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-11-14 11:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0030_merge_20231113_1518"),
]

operations = [
migrations.AddField(
model_name="zaaktypeconfig",
name="url",
field=models.URLField(blank=True, verbose_name="Zaaktype URL"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.2.20 on 2023-11-14 11:26

from django.db import migrations
from django.db import transaction
from open_inwoner.openzaak.zgw_imports import get_configurable_zaaktypes
from django.core.exceptions import ObjectDoesNotExist


def populate_zaaktype_config_urls(apps, schema_editor):
"""
Go through configurable zaaktypen and populate the new URL field where needed
"""
ZaakTypeConfig = apps.get_model("openzaak", "ZaakTypeConfig")
CatalogusConfig = apps.get_model("openzaak", "CatalogusConfig")
catalog_lookup = {c.url: c for c in CatalogusConfig.objects.all()}

zaaktypes = get_configurable_zaaktypes()
if not zaaktypes:
return []

with transaction.atomic():
for zaaktype in zaaktypes:
catalog = catalog_lookup.get(zaaktype.catalogus)
if not catalog:
continue

try:
config = ZaakTypeConfig.objects.get(
url="", catalogus=catalog, identificatie=zaaktype.identificatie
)
config.url = zaaktype.url
config.save()
except ObjectDoesNotExist:
continue


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0031_zaaktypeconfig_url"),
]

operations = [
migrations.RunPython(populate_zaaktype_config_urls, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-11-14 11:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0032_populate_zaaktype_urls"),
]

operations = [
migrations.AlterField(
model_name="zaaktypeconfig",
name="url",
field=models.URLField(unique=True, verbose_name="Zaaktype URL"),
),
]
4 changes: 4 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def __str__(self):


class ZaakTypeConfig(models.Model):
url = models.URLField(
verbose_name=_("Zaaktype URL"),
unique=True,
)
catalogus = models.ForeignKey(
"openzaak.CatalogusConfig",
on_delete=models.CASCADE,
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Meta:


class ZaakTypeConfigFactory(factory.django.DjangoModelFactory):
url = factory.Faker("url")
catalogus = factory.SubFactory(CatalogusConfigFactory)
identificatie = factory.Faker("pystr", max_chars=50)
omschrijving = factory.Faker("pystr", max_chars=80)
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/openzaak/zgw_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def import_zaaktype_configs() -> List[ZaakTypeConfig]:
known_keys.add(key)
create.append(
ZaakTypeConfig(
url=zaak_type.url,
catalogus=catalog,
identificatie=zaak_type.identificatie,
omschrijving=zaak_type.omschrijving,
Expand Down

0 comments on commit 58a2138

Please sign in to comment.