@@ -293,21 +293,16 @@ def connect_case_with_document(case_url: str, document_url: str) -> Optional[dic
293
293
return response
294
294
295
295
296
- def resolve_zaak_type (cases : list [ Zaak ] ) -> None :
296
+ def resolve_zaak_type (case : Zaak ) -> None :
297
297
"""
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
307
299
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
311
306
312
307
313
308
def resolve_status (case : Zaak ) -> None :
@@ -317,31 +312,29 @@ def resolve_status(case: Zaak) -> None:
317
312
case .status = fetch_single_status (case .status )
318
313
319
314
320
- def add_status_type_config (case : Zaak ):
315
+ def resolve_status_type (case : Zaak ) -> None :
321
316
"""
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
+
323
322
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 :
326
324
"""
327
- case_statustype_url = case . status . statustype
325
+ Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case
328
326
327
+ Note: must be called after `resolve_status_type` since we're getting the
328
+ status type url from `case.status.statustype`
329
+ """
329
330
try :
330
331
case .statustype_config = ZaakTypeStatusTypeConfig .objects .get (
331
- statustype_url = case_statustype_url
332
+ statustype_url = case . status . statustype . url
332
333
)
333
334
except ZaakTypeStatusTypeConfig .DoesNotExist :
334
335
pass
335
336
336
337
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
-
345
338
def filter_visible (cases : list [Zaak ]) -> list [Zaak ]:
346
339
return [case for case in cases if is_zaak_visible (case )]
347
340
@@ -350,11 +343,12 @@ def preprocess_data(cases: list[Zaak]) -> list[Zaak]:
350
343
"""
351
344
Resolve zaaktype and statustype, add status type config, filter for visibility
352
345
"""
353
- resolve_zaak_type (cases )
346
+ for case in cases :
347
+ resolve_zaak_type (case )
354
348
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 )
359
353
360
354
return filter_visible (cases )
0 commit comments