Skip to content

Commit

Permalink
[#1050] Added usable columns to ZaakTypeConfig admin, fixed some test…
Browse files Browse the repository at this point in the history
… issues

Also regenerated the migration
  • Loading branch information
Bart van der Schoor committed Feb 8, 2023
1 parent baf316d commit 7c10355
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
47 changes: 46 additions & 1 deletion src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin, messages
from django.core.exceptions import ValidationError
from django.db.models import Count
from django.db.models import BooleanField, Count, Exists, ExpressionWrapper, Q
from django.forms.models import BaseInlineFormSet
from django.utils.translation import gettext_lazy as _, ngettext

Expand Down Expand Up @@ -42,6 +42,25 @@ class CatalogusConfigAdmin(admin.ModelAdmin):
ordering = ("domein", "rsin")


class HasDocNotifyListFilter(admin.SimpleListFilter):
title = _("notify document attachment")
parameter_name = "doc_notify"

def lookups(self, request, model_admin):
return [
("yes", _("Yes")),
("no", _("No")),
]

def queryset(self, request, queryset):
v = self.value()
if v == "yes":
queryset = queryset.filter(has_doc_notify=True)
elif v == "no":
queryset = queryset.filter(has_doc_notify=False)
return queryset


class CatalogUsedListFilter(admin.SimpleListFilter):
title = _("Catalogus")
parameter_name = "catalogus"
Expand Down Expand Up @@ -129,6 +148,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin):
"omschrijving",
"catalogus",
"notify_status_changes",
"has_doc_notify",
"document_upload_enabled",
"num_infotypes",
]
Expand All @@ -138,6 +158,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin):
]
list_filter = [
"notify_status_changes",
HasDocNotifyListFilter,
CatalogUsedListFilter,
]
search_fields = [
Expand All @@ -157,6 +178,19 @@ def has_delete_permission(self, request, obj=None):
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.annotate(num_infotypes=Count("zaaktypeinformatieobjecttypeconfig"))
qs = qs.annotate(
num_doc_notify=Count(
"zaaktypeinformatieobjecttypeconfig",
filter=Q(
zaaktypeinformatieobjecttypeconfig__document_notification_enabled=True
),
)
)
qs = qs.annotate(
has_doc_notify=ExpressionWrapper(
Q(num_doc_notify__gt=0), output_field=BooleanField()
)
)
return qs

def num_infotypes(self, obj=None):
Expand All @@ -165,6 +199,17 @@ def num_infotypes(self, obj=None):
else:
return getattr(obj, "num_infotypes", 0)

num_infotypes.admin_order_field = "num_infotypes"

def has_doc_notify(self, obj=None):
if not obj or not obj.pk:
return False
else:
return getattr(obj, "has_doc_notify", False)

has_doc_notify.boolean = True
has_doc_notify.admin_order_field = "has_doc_notify"

@admin.action(description="Set selected Zaaktypes to notify on status changes")
def mark_as_notify_status_changes(self, request, qs):
count = qs.update(notify_status_changes=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.15 on 2023-02-07 14:32
# Generated by Django 3.2.15 on 2023-02-08 09:34

from django.db import migrations, models

Expand All @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
field=models.BooleanField(
default=False,
help_text="When enabled the user will receive a notification when a visible document is added to the case",
verbose_name="Enable document notification",
verbose_name="Enable document notifications",
),
),
]
11 changes: 8 additions & 3 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ class Meta:

def informatieobjecttype_uuid(self):
if self.informatieobjecttype_url:
s = furl(self.informatieobjecttype_url).path.segments
# handle trailing slash
return s[-1] or s[-2] or self.informatieobjecttype_url
segments = furl(self.informatieobjecttype_url).path.segments
# grab uuid as last bit of url,
# but handle trailing slash or weird urls from factories
while segments:
s = segments.pop()
if s:
return s
return self.informatieobjecttype_url
return ""

informatieobjecttype_uuid.short_description = _("Information object UUID")
Expand Down
7 changes: 0 additions & 7 deletions src/open_inwoner/openzaak/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
from open_inwoner.openzaak.tests.shared import CATALOGI_ROOT


class Reminder(TestCase):
def test_admin(self):
self.fail(
"check ticket and update admin list view with a column to indicate which ZaakTypeConfig has info object types with upload"
)


class ZaakTypeConfigModelTestCase(TestCase):
def test_queryset_filter_case_type_with_catalog(self):
catalog = CatalogusConfigFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_zio_bails_when_zaak_type_info_object_type_config_is_found_not_marked_fo

mock_handle.assert_not_called()
self.assertTimelineLog(
f"ignored zaakinformatieobject notification: info_type configuration 'important documentl' {data.informatie_object['informatieobjecttype']} found but 'document_notification_enabled' is False for case https://",
f"ignored zaakinformatieobject notification: info_type configuration 'important document' {data.informatie_object['informatieobjecttype']} found but 'document_notification_enabled' is False for case https://",
lookup=Lookups.startswith,
level=logging.INFO,
)
Expand Down

0 comments on commit 7c10355

Please sign in to comment.