Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#1789] Add ZaakTypeStatusTypeConfig model #803

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/open_inwoner/cms/cases/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
fetch_single_case_type,
fetch_single_status_type,
)
from open_inwoner.openzaak.models import OpenZaakConfig, StatusTranslation
from open_inwoner.openzaak.models import (
OpenZaakConfig,
StatusTranslation,
ZaakTypeStatusTypeConfig,
)
from open_inwoner.openzaak.utils import format_zaak_identificatie, is_zaak_visible
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import LogMixin
Expand Down Expand Up @@ -110,6 +114,11 @@ def get_cases(self) -> List[Zaak]:
case_types = {}
case_types_set = {case.zaaktype for case in cases}

mapping = {
zaaktype_statustype.statustype_url: zaaktype_statustype
for zaaktype_statustype in ZaakTypeStatusTypeConfig.objects.all()
}

# fetch unique case types
for case_type_url in case_types_set:
# todo parallel
Expand All @@ -130,6 +139,8 @@ def get_cases(self) -> List[Zaak]:
case.status = fetch_single_status(case.status)
status_types[case.status.statustype].append(case)

case.statustype_config = mapping.get(case.status.statustype)

for status_type_url, _cases in status_types.items():
# todo parallel
status_type = fetch_single_status_type(status_type_url)
Expand All @@ -154,6 +165,7 @@ def process_cases(self, cases: List[Zaak]) -> List[dict]:
"current_status": status_translate.from_glom(
case, "status.statustype.omschrijving", default=""
),
"statustype_config": getattr(case, "statustype_config"),
}
updated_cases.append(case_dict)
return updated_cases
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load icon_tags %}
stevenbal marked this conversation as resolved.
Show resolved Hide resolved
<div class="card__header {{ status_indicator }}">
{% if status_indicator == "success" %}
{% icon icon="check_circle" icon_position="after" extra_classes="icon--"|add:status_indicator %} {{status_indicator_text}}
{% elif status_indicator == "failure" %}
{% icon icon="cancel" icon_position="after" extra_classes="icon--"|add:status_indicator %} {{status_indicator_text}}
{% else %}
{% icon icon=status_indicator icon_position="after" extra_classes="icon--"|add:status_indicator %} {{status_indicator_text}}
{% endif %}
</div>
30 changes: 30 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeStatusTypeConfig,
)
from .resources.import_resource import StatusTranslationImportResource

Expand Down Expand Up @@ -157,10 +158,39 @@ def has_delete_permission(self, request, obj=None):
return request.user.is_superuser


class ZaakTypeStatusTypeConfigInline(admin.TabularInline):
model = ZaakTypeStatusTypeConfig
fields = [
"statustekst",
"omschrijving",
"statustype_url",
"zaaktype_uuids",
"status_indicator",
"status_indicator_text",
]
readonly_fields = [
"statustekst",
"omschrijving",
"statustype_url",
"zaaktype_uuids",
]
ordering = (
"zaaktype_uuids",
"omschrijving",
)

def has_add_permission(self, request, obj):
return False

def has_delete_permission(self, request, obj=None):
return request.user.is_superuser


@admin.register(ZaakTypeConfig)
class ZaakTypeConfigAdmin(admin.ModelAdmin):
inlines = [
ZaakTypeInformatieObjectTypeConfigInline,
ZaakTypeStatusTypeConfigInline,
]
actions = [
"mark_as_notify_status_changes",
Expand Down
9 changes: 9 additions & 0 deletions src/open_inwoner/openzaak/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models
from django.utils.translation import gettext_lazy as _


class StatusIndicators(models.TextChoices):
info = "info", _("Info")
warning = "warning", _("Warning")
failure = "failure", _("Failure")
success = "success", _("Success")
11 changes: 11 additions & 0 deletions src/open_inwoner/openzaak/management/commands/zgw_import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import_catalog_configs,
import_zaaktype_configs,
import_zaaktype_informatieobjecttype_configs,
import_zaaktype_statustype_configs,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -42,3 +43,13 @@ def handle(self, *args, **options):
self.stdout.write(f" {c}")

self.stdout.write("")

imported = import_zaaktype_statustype_configs()

count = sum(len(t[1]) for t in imported)

self.stdout.write(f"imported {count} new zaaktype-statustype configs")
for ztc, status_types in sorted(imported, key=lambda t: str(t[0])):
self.stdout.write(str(ztc))
for c in sorted(map(str, status_types)):
self.stdout.write(f" {c}")
90 changes: 90 additions & 0 deletions src/open_inwoner/openzaak/migrations/0025_auto_20231016_0957.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 3.2.20 on 2023-10-16 07:57

from django.db import migrations, models
import django.db.models.deletion
import django_better_admin_arrayfield.models.fields


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0024_zaaktypeconfig_contact_subject_code"),
]

operations = [
migrations.CreateModel(
name="ZaakTypeStatusTypeConfig",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"statustype_url",
models.URLField(max_length=1000, verbose_name="Statustype URL"),
),
(
"omschrijving",
models.CharField(max_length=80, verbose_name="Omschrijving"),
),
(
"statustekst",
models.CharField(max_length=1000, verbose_name="Statustekst"),
),
(
"zaaktype_uuids",
django_better_admin_arrayfield.models.fields.ArrayField(
base_field=models.UUIDField(verbose_name="Zaaktype UUID"),
default=list,
size=None,
),
),
(
"status_indicator",
models.CharField(
blank=True,
choices=[
("info", "Info"),
("warning", "Warning"),
("failure", "Failure"),
("success", "Success"),
],
help_text="Determines what will be shown to the user if a case is set to this status",
max_length=32,
verbose_name="Statustype indicator",
),
),
(
"status_indicator_text",
models.TextField(
blank=True,
default="",
help_text="Determines the text that will be shown to the user if a case is set to this status",
verbose_name="Statustype indicator",
),
),
(
"zaaktype_config",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="openzaak.zaaktypeconfig",
),
),
],
options={
"verbose_name": "Zaaktype Statustype Configuration",
},
),
migrations.AddConstraint(
model_name="zaaktypestatustypeconfig",
constraint=models.UniqueConstraint(
fields=("zaaktype_config", "statustype_url"),
name="unique_zaaktype_config_statustype_url",
),
),
]
59 changes: 59 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
ZaakTypeInformatieObjectTypeConfigQueryset,
)

from .constants import StatusIndicators


def generate_default_file_extensions():
return sorted(
Expand Down Expand Up @@ -300,6 +302,63 @@ def __str__(self):
return self.omschrijving


class ZaakTypeStatusTypeConfig(models.Model):
zaaktype_config = models.ForeignKey(
"openzaak.ZaakTypeConfig",
on_delete=models.CASCADE,
)
statustype_url = models.URLField(
verbose_name=_("Statustype URL"),
max_length=1000,
)
omschrijving = models.CharField(
verbose_name=_("Omschrijving"),
max_length=80,
)
statustekst = models.CharField(
verbose_name=_("Statustekst"),
max_length=1000,
)
zaaktype_uuids = ArrayField(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is in there as we already have a relation with a zaaktype_config. But as this is done this way for the ZTIOT-Config I guess there is a purpose...

models.UUIDField(
verbose_name=_("Zaaktype UUID"),
),
default=list,
)

# configuration
status_indicator = models.CharField(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to name this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indicator would have been fine

blank=True,
max_length=32,
choices=StatusIndicators.choices,
verbose_name=_("Statustype indicator"),
help_text=_(
"Determines what will be shown to the user if a case is set to this status"
),
)
status_indicator_text = models.TextField(
stevenbal marked this conversation as resolved.
Show resolved Hide resolved
blank=True,
default="",
verbose_name=_("Statustype indicator"),
help_text=_(
"Determines the text that will be shown to the user if a case is set to this status"
),
)

class Meta:
verbose_name = _("Zaaktype Statustype Configuration")

constraints = [
UniqueConstraint(
name="unique_zaaktype_config_statustype_url",
fields=["zaaktype_config", "statustype_url"],
)
]

def __str__(self):
return f"{self.zaaktype_config.identificatie} - {self.omschrijving}"


class UserCaseStatusNotificationBase(models.Model):
user = models.ForeignKey(
"accounts.User",
Expand Down
10 changes: 10 additions & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeStatusTypeConfig,
)


Expand Down Expand Up @@ -111,6 +112,15 @@ def from_case_type_info_object_dicts(
return ZaakTypeInformatieObjectTypeConfigFactory(**kwargs)


class ZaakTypeStatusTypeConfigFactory(factory.django.DjangoModelFactory):
zaaktype_config = factory.SubFactory(ZaakTypeConfigFactory)
statustype_url = factory.Faker("url")
omschrijving = factory.Faker("pystr", max_chars=80)

class Meta:
model = ZaakTypeStatusTypeConfig


class UserCaseStatusNotificationFactory(factory.django.DjangoModelFactory):
user = factory.SubFactory(UserFactory)
case_uuid = factory.Faker("uuid4")
Expand Down
Loading
Loading