Skip to content

Commit 7a9263e

Browse files
SilviaAmAmsvenvandescheur
authored andcommitted
♻️ [#303] Refactor making the zaaktype choices
1 parent d68f9fd commit 7a9263e

File tree

1 file changed

+18
-10
lines changed
  • backend/src/openarchiefbeheer/zaken

1 file changed

+18
-10
lines changed

backend/src/openarchiefbeheer/zaken/utils.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ def expand_procestype(zaak: dict) -> dict:
8484
return processed_zaken
8585

8686

87+
def _format_zaaktypen_choices(
88+
zaaktypen: list, zaaktypen_to_include: list | None = None
89+
) -> list[DropDownChoice]:
90+
formatted_choices = []
91+
for key, value in zaaktypen.items():
92+
item = {"label": key or _("(no identificatie)"), "value": ",".join(value)}
93+
if zaaktypen_to_include is None:
94+
formatted_choices.append(item)
95+
continue
96+
97+
if key in zaaktypen_to_include:
98+
formatted_choices.append(item)
99+
100+
return sorted(formatted_choices, key=lambda zaaktype: zaaktype["label"])
101+
102+
87103
def retrieve_zaaktypen_choices() -> list[DropDownChoice]:
88104
ztc_service = Service.objects.filter(api_type=APITypes.ztc).first()
89105
if not ztc_service:
@@ -108,12 +124,7 @@ def retrieve_zaaktypen_choices() -> list[DropDownChoice]:
108124
.values_list("_expand__zaaktype__identificatie", flat=True)
109125
.distinct()
110126
)
111-
zaaktypen_choices = [
112-
{"label": key or _("(no identificatie)"), "value": ",".join(value)}
113-
for key, value in zaaktypen.items()
114-
if key in zaaktypes_to_include
115-
]
116-
return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
127+
return _format_zaaktypen_choices(zaaktypen, zaaktypes_to_include)
117128

118129

119130
def _get_zaaktype_choices(zaaktypen_to_include: dict[list]) -> list[DropDownChoice]:
@@ -125,10 +136,7 @@ def _get_zaaktype_choices(zaaktypen_to_include: dict[list]) -> list[DropDownChoi
125136
for zaaktype_url, zaaktype_identificatie in zaaktypen_to_include:
126137
zaaktypen[zaaktype_identificatie].append(zaaktype_url)
127138

128-
zaaktypen_choices = [
129-
{"label": key, "value": ",".join(value)} for key, value in zaaktypen.items()
130-
]
131-
return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
139+
return _format_zaaktypen_choices(zaaktypen)
132140

133141

134142
def get_zaaktypen_choices_from_list(

0 commit comments

Comments
 (0)