Skip to content

Commit

Permalink
Fixed case filtering in list view and AttributeError in detail view
Browse files Browse the repository at this point in the history
  - 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`
  • Loading branch information
pi-sigma committed Oct 31, 2023
1 parent fd379ad commit 8f490df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 12 additions & 9 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8f490df

Please sign in to comment.