From 8f490df045c82942a86274e7bc65f4b9bc4a88d6 Mon Sep 17 00:00:00 2001 From: Paul Schilling Date: Fri, 27 Oct 2023 16:35:47 +0200 Subject: [PATCH] Fixed case filtering in list view and AttributeError in detail view - solves two issues resulting from the recent refactor of the case list view and modifications made to the detail view: the case filtering was done in the wrong place, slowing down page load; the detail view occasionally raised an error when accessing `case.status` --- src/open_inwoner/cms/cases/views/cases.py | 1 - src/open_inwoner/cms/cases/views/status.py | 6 ++++-- src/open_inwoner/openzaak/cases.py | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/open_inwoner/cms/cases/views/cases.py b/src/open_inwoner/cms/cases/views/cases.py index 19e3c82f46..fe1405fa3a 100644 --- a/src/open_inwoner/cms/cases/views/cases.py +++ b/src/open_inwoner/cms/cases/views/cases.py @@ -45,7 +45,6 @@ def page_title(self): def get_cases(self): raw_cases = fetch_cases(self.request.user.bsn) preprocessed_cases = preprocess_data(raw_cases) - preprocessed_cases.sort(key=lambda case: case.startdatum, reverse=True) return preprocessed_cases def get_submissions(self): diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index d87bec77e0..afe127bbc6 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -201,11 +201,13 @@ def get_upload_info_context(self, case: Zaak): zt_statustype_config = ztc.zaaktypestatustypeconfig_set.get( statustype_url=case.status.statustype.url ) + # case has no status, or status type not found + except (AttributeError, ObjectDoesNotExist): + pass + else: case_type_document_upload_description = ( zt_statustype_config.document_upload_description ) - except ObjectDoesNotExist: - pass return { "case_type_config_description": case_type_config_description, diff --git a/src/open_inwoner/openzaak/cases.py b/src/open_inwoner/openzaak/cases.py index 9dc7cb5f1a..d33866f8d8 100644 --- a/src/open_inwoner/openzaak/cases.py +++ b/src/open_inwoner/openzaak/cases.py @@ -335,20 +335,23 @@ def add_status_type_config(case: Zaak) -> None: pass -def filter_visible(cases: list[Zaak]) -> list[Zaak]: - return [case for case in cases if is_zaak_visible(case)] - - def preprocess_data(cases: list[Zaak]) -> list[Zaak]: """ Resolve zaaktype and statustype, add status type config, filter for visibility + + Note: we need to iterate twice over `cases` because the `zaak_type` must be + resolved to a `ZaakType` object before we can filter by visibility """ for case in cases: resolve_zaak_type(case) - if case.status: - resolve_status(case) - resolve_status_type(case) - add_status_type_config(case) + cases = [case for case in cases if case.status and is_zaak_visible(case)] - return filter_visible(cases) + for case in cases: + resolve_status(case) + resolve_status_type(case) + add_status_type_config(case) + + cases.sort(key=lambda case: case.startdatum, reverse=True) + + return cases