Skip to content

Commit fbef4a4

Browse files
committed
[#1788] Process PR feedback
1 parent 081b028 commit fbef4a4

File tree

15 files changed

+146
-155
lines changed

15 files changed

+146
-155
lines changed

src/open_inwoner/cms/cases/urls.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django.urls import path
2-
from django.views.generic import RedirectView
32

43
from open_inwoner.accounts.views.contactmoments import (
54
KlantContactMomentDetailView,
@@ -54,7 +53,6 @@
5453
CaseDocumentUploadFormView.as_view(),
5554
name="case_detail_document_form",
5655
),
57-
path("open/", RedirectView.as_view(), name="redirect"),
5856
path("content/", InnerCaseListView.as_view(), name="cases_content"),
5957
path("", OuterCaseListView.as_view(), name="index"),
6058
]

src/open_inwoner/cms/cases/views/cases.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
from django.urls import reverse
2-
from django.utils.functional import cached_property
32
from django.utils.translation import gettext_lazy as _
43
from django.views.generic import TemplateView
54

6-
from view_breadcrumbs import BaseBreadcrumbMixin
7-
85
from open_inwoner.htmx.mixins import RequiresHtmxMixin
96
from open_inwoner.openzaak.cases import fetch_cases, preprocess_data
107
from open_inwoner.openzaak.formapi import fetch_open_submissions
118
from open_inwoner.openzaak.models import OpenZaakConfig
9+
from open_inwoner.openzaak.types import UniformCase
1210
from open_inwoner.utils.mixins import PaginationMixin
1311
from open_inwoner.utils.views import CommonPageMixin
1412

1513
from .mixins import CaseAccessMixin, CaseLogMixin, OuterCaseAccessMixin
1614

1715

18-
class OuterCaseListView(
19-
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
20-
):
21-
"""View on case list while being loaded"""
16+
class OuterCaseListView(OuterCaseAccessMixin, CommonPageMixin, TemplateView):
17+
"""View on the case list while content is loaded via htmx"""
2218

2319
template_name = "pages/cases/list_outer.html"
2420

2521
def page_title(self):
2622
return _("Mijn aanvragen")
2723

28-
@cached_property
29-
def crumbs(self):
30-
return [(_("Mijn aanvragen"), reverse("cases:redirect"))]
31-
3224
def get_context_data(self, **kwargs):
3325
context = super().get_context_data(**kwargs)
3426

@@ -44,8 +36,6 @@ class InnerCaseListView(
4436
PaginationMixin,
4537
TemplateView,
4638
):
47-
"""View on case list"""
48-
4939
template_name = "pages/cases/list_inner.html"
5040
paginate_by = 9
5141

@@ -67,9 +57,9 @@ def get_context_data(self, **kwargs):
6757
context = super().get_context_data(**kwargs)
6858
config = OpenZaakConfig.get_solo()
6959

70-
# update ctx with cases + submissions
71-
preprocessed_cases = self.get_cases()
72-
open_submissions = self.get_submissions()
60+
# update ctx with submissions + cases
61+
open_submissions: list[UniformCase] = self.get_submissions()
62+
preprocessed_cases: list[UniformCase] = self.get_cases()
7363
paginator_dict = self.paginate_with_context(
7464
[*open_submissions, *preprocessed_cases]
7565
)

src/open_inwoner/cms/cases/views/mixins.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@
1818
class CaseLogMixin(LogMixin):
1919
def log_access_cases(self, cases: list[dict]):
2020
"""
21-
Log access to cases on the list view (create single log for all cases)
21+
Log access to cases on the list view
22+
23+
Creates a single log for all cases
2224
"""
23-
case_ids = (case["identificatie"] for case in cases)
25+
case_ids = (case["identification"] for case in cases)
2426

2527
self.log_user_action(
2628
self.request.user,
27-
_("Zaaken bekeken: {cases}").format(cases=", ".join(case_ids)),
29+
_("Zaken bekeken: {cases}").format(cases=", ".join(case_ids)),
2830
)
2931

3032
def log_access_case_detail(self, case: UniformCase):
31-
"""
32-
Log access to a particular case
33-
"""
3433
self.log_user_action(
3534
self.request.user,
36-
_("Zaak bekeken: {case}").format(case=case.identificatie),
35+
_("Zaak bekeken: {case}").format(case=case.identification),
3736
)
3837

3938

src/open_inwoner/cms/cases/views/status.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def get_context_data(self, **kwargs):
136136

137137
context["case"] = {
138138
"id": str(self.case.uuid),
139-
"identification": self.case.format_zaak_identificatie(
140-
self.case.identificatie, config
141-
),
139+
"identification": self.case.identification,
142140
"initiator": self.get_initiator_display(self.case),
143141
"result": self.get_result_display(self.case),
144142
"start_date": self.case.startdatum,

src/open_inwoner/openzaak/api_models.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Zaak(ZGWModel):
3838
# zaakgeometrie: dict
3939

4040
@staticmethod
41-
def _reformat_esuite_zaak_identificatie(identificatie: str):
41+
def _reformat_esuite_zaak_identificatie(identificatie: str) -> str:
4242
"""
4343
0014ESUITE66392022 -> 6639-2022
4444
@@ -52,28 +52,29 @@ def _reformat_esuite_zaak_identificatie(identificatie: str):
5252
year = m.group("year")
5353
return f"{num}-{year}"
5454

55-
def format_zaak_identificatie(
56-
self,
57-
identificatie: str,
58-
zaak_config: "OpenZaakConfig",
59-
):
55+
def _format_zaak_identificatie(self) -> str:
56+
from open_inwoner.openzaak.models import OpenZaakConfig
57+
58+
zaak_config = OpenZaakConfig.get_solo()
59+
6060
if zaak_config.reformat_esuite_zaak_identificatie:
6161
return self._reformat_esuite_zaak_identificatie(self.identificatie)
62-
return identificatie
62+
return self.identificatie
6363

64-
def process_data(self):
64+
@property
65+
def identification(self) -> str:
66+
return self._format_zaak_identificatie()
67+
68+
def process_data(self) -> dict:
6569
"""
6670
Prepare data for template
6771
"""
68-
from open_inwoner.openzaak.models import OpenZaakConfig, StatusTranslation
72+
from open_inwoner.openzaak.models import StatusTranslation
6973

70-
zaak_config = OpenZaakConfig.get_solo()
7174
status_translate = StatusTranslation.objects.get_lookup()
7275

7376
return {
74-
"identificatie": self.format_zaak_identificatie(
75-
self.identificatie, zaak_config
76-
),
77+
"identification": self.identification,
7778
"uuid": str(self.uuid),
7879
"start_date": self.startdatum,
7980
"end_date": getattr(self, "einddatum", None),
@@ -82,6 +83,7 @@ def process_data(self):
8283
self, "status.statustype.omschrijving", default=""
8384
),
8485
"statustype_config": getattr(self, "statustype_config", None),
86+
"case_type": "Zaak",
8587
}
8688

8789

src/open_inwoner/openzaak/cases.py

+26-32
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,16 @@ def connect_case_with_document(case_url: str, document_url: str) -> Optional[dic
293293
return response
294294

295295

296-
def resolve_zaak_type(cases: list[Zaak]) -> None:
296+
def resolve_zaak_type(case: Zaak) -> None:
297297
"""
298-
Resolve zaaktype for each case
299-
"""
300-
case_types = {}
301-
case_types_set = {case.zaaktype for case in cases}
302-
303-
# fetch unique case types
304-
for case_type_url in case_types_set:
305-
# todo parallel
306-
case_types[case_type_url] = fetch_single_case_type(case_type_url)
298+
Resolve `case.zaaktype` (`str`) to a `ZaakType(ZGWModel)` object
307299
308-
# set resolved case types
309-
for case in cases:
310-
case.zaaktype = case_types[case.zaaktype]
300+
Note: the result of `fetch_single_case_type` is cached, hence a request
301+
is only made for new case type urls
302+
"""
303+
case_type_url = case.zaaktype
304+
case_type = fetch_single_case_type(case_type_url)
305+
case.zaaktype = case_type
311306

312307

313308
def resolve_status(case: Zaak) -> None:
@@ -317,31 +312,29 @@ def resolve_status(case: Zaak) -> None:
317312
case.status = fetch_single_status(case.status)
318313

319314

320-
def add_status_type_config(case: Zaak):
315+
def resolve_status_type(case: Zaak) -> None:
321316
"""
322-
Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case
317+
Resolve `case.statustype` (`str`) to a `StatusType(ZGWModel)` object
318+
"""
319+
statustype_url = case.status.statustype
320+
case.status.statustype = fetch_single_status_type(statustype_url)
321+
323322

324-
Note: must be called before the call to `resolve_status_type`, since we need
325-
the unresolved status type url here
323+
def add_status_type_config(case: Zaak) -> None:
326324
"""
327-
case_statustype_url = case.status.statustype
325+
Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case
328326
327+
Note: must be called after `resolve_status_type` since we're getting the
328+
status type url from `case.status.statustype`
329+
"""
329330
try:
330331
case.statustype_config = ZaakTypeStatusTypeConfig.objects.get(
331-
statustype_url=case_statustype_url
332+
statustype_url=case.status.statustype.url
332333
)
333334
except ZaakTypeStatusTypeConfig.DoesNotExist:
334335
pass
335336

336337

337-
def resolve_status_type(case: Zaak) -> None:
338-
"""
339-
Resolve `case.statustype` (`str`) to a `StatusType(ZGWModel)` object
340-
"""
341-
statustype_url = case.status.statustype
342-
case.status.statustype = fetch_single_status_type(statustype_url)
343-
344-
345338
def filter_visible(cases: list[Zaak]) -> list[Zaak]:
346339
return [case for case in cases if is_zaak_visible(case)]
347340

@@ -350,11 +343,12 @@ def preprocess_data(cases: list[Zaak]) -> list[Zaak]:
350343
"""
351344
Resolve zaaktype and statustype, add status type config, filter for visibility
352345
"""
353-
resolve_zaak_type(cases)
346+
for case in cases:
347+
resolve_zaak_type(case)
354348

355-
for case in filter(lambda case: case.status, cases):
356-
resolve_status(case)
357-
add_status_type_config(case)
358-
resolve_status_type(case)
349+
if case.status:
350+
resolve_status(case)
351+
resolve_status_type(case)
352+
add_status_type_config(case)
359353

360354
return filter_visible(cases)

src/open_inwoner/openzaak/catalog.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
import logging
2-
from typing import List, Optional, Union
3-
from uuid import UUID
2+
from typing import List, Optional
43

54
from django.conf import settings
65

76
from requests import RequestException
8-
from zds_client import ClientError, get_operation_url
7+
from zds_client import ClientError
98
from zgw_consumers.api_models.base import factory
109
from zgw_consumers.api_models.catalogi import Catalogus
1110
from zgw_consumers.service import get_paginated_results
1211

1312
from ..utils.decorators import cache as cache_result
1413
from .api_models import InformatieObjectType, ResultaatType, StatusType, ZaakType
1514
from .clients import build_client
15+
from .utils import get_retrieve_resource_by_uuid_url
1616

1717
logger = logging.getLogger(__name__)
1818

1919

20-
def get_retrieve_resource_by_uuid_url(
21-
client, resource: str, uuid: Union[str, UUID]
22-
) -> str:
23-
op_suffix = client.operation_suffix_mapping["retrieve"]
24-
operation_id = f"{resource}{op_suffix}"
25-
path_kwargs = {
26-
"uuid": uuid,
27-
}
28-
url = get_operation_url(
29-
client.schema, operation_id, base_url=client.base_url, **path_kwargs
30-
)
31-
return url
32-
33-
3420
# not cached because only used by tools,
3521
# and because caching (stale) listings can break lookups
3622
def fetch_status_types_no_cache(case_type_url: str) -> List[StatusType]:

src/open_inwoner/openzaak/formapi.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ class OpenSubmission(Model):
2323
eind_datum_geldigheid: Optional[datetime] = None
2424

2525
@property
26-
def identificatie(self):
26+
def identification(self) -> str:
2727
return f"{self.naam}: {self.uuid}"
2828

29-
def process_data(self):
29+
def process_data(self) -> dict:
30+
"""
31+
Prepare data for template
32+
"""
3033
return {
34+
"identification": self.identification,
3135
"url": self.url,
3236
"uuid": self.uuid,
3337
"naam": self.naam,
34-
"identificatie": self.identificatie,
3538
"vervolg_link": self.vervolg_link,
3639
"datum_laatste_wijziging": self.datum_laatste_wijziging,
3740
"eind_datum_geldigheid": self.eind_datum_geldigheid or "Geen",
41+
"case_type": "OpenSubmission",
3842
}
3943

4044

src/open_inwoner/openzaak/notifications.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,13 @@ def send_case_update_email(user: User, case: Zaak):
357357
"""
358358
send the actual mail
359359
"""
360-
config = OpenZaakConfig.get_solo()
361-
362360
case_detail_url = build_absolute_url(
363361
reverse("cases:case_detail", kwargs={"object_id": str(case.uuid)})
364362
)
365363

366364
template = find_template("case_notification")
367365
context = {
368-
"identification": case.format_zaak_identificatie(case.identificatie, config),
366+
"identification": case.identification,
369367
"type_description": case.zaaktype.omschrijving,
370368
"start_date": case.startdatum,
371369
"case_link": case_detail_url,

src/open_inwoner/openzaak/tests/test_case_detail.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
from ...utils.tests.helpers import AssertRedirectsMixin
3434
from ..api_models import Status, StatusType
3535
from ..models import OpenZaakConfig
36-
37-
# TODO delete
38-
# from ..utils import format_zaak_identificatie
3936
from .factories import CatalogusConfigFactory, ServiceFactory
4037
from .shared import CATALOGI_ROOT, DOCUMENTEN_ROOT, ZAKEN_ROOT
4138

@@ -414,11 +411,13 @@ def test_page_reformats_zaak_identificatie(self, m):
414411
self._setUpMocks(m)
415412

416413
with patch(
417-
"open_inwoner.openzaak.api_models.Zaak.format_zaak_identificatie",
414+
"open_inwoner.openzaak.api_models.Zaak._format_zaak_identificatie",
418415
) as spy_format:
419416
self.app.get(self.case_detail_url, user=self.user)
420417

421-
spy_format.assert_called_once()
418+
# _format_zaak_identificatie is called twice on requesting DetailVew:
419+
# once for the log, once for adding case to context
420+
spy_format.assert_called
422421

423422
def test_page_translates_statuses(self, m):
424423
st1 = StatusTranslationFactory(

0 commit comments

Comments
 (0)