Skip to content

Commit

Permalink
[#2217] Process PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Mar 20, 2024
1 parent b305fb6 commit 79c90b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
17 changes: 7 additions & 10 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,9 @@ def handle_end_statustype_data(
end_statustype_data = None
if not status_types_mapping.get(end_statustype.url):
end_statustype_data = {
"label": (
end_statustype.statustekst
or status_translate(
end_statustype.omschrijving, default=_("No data available")
)
"label": status_translate(
(end_statustype.statustekst or end_statustype.omschrijving),
default=_("No data available"),
),
"status_indicator": getattr(
self.statustype_config_mapping.get(end_statustype.url),
Expand Down Expand Up @@ -544,11 +542,10 @@ def get_statuses_data(
return [
{
"date": s.datum_status_gezet,
"label": (
s.statustype.statustekst
or lookup.from_glom(
s, "statustype.omschrijving", default=_("No data available")
)
"label": lookup.from_glom_multiple(
s,
("statustype.statustekst", "statustype.omschrijving"),
default=_("No data available"),
),
"status_indicator": getattr(
statustype_config_mapping.get(s.statustype.url),
Expand Down
21 changes: 15 additions & 6 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,21 +1372,30 @@ def test_page_reformats_zaak_identificatie(self, m):
spy_format.assert_called

def test_page_translates_statuses(self, m):
st1 = StatusTranslationFactory(
trans_status_new_omschrijving = StatusTranslationFactory(
status=self.status_type_new["omschrijving"],
translation="Translated First Status Type",
translation="Translated First Status Type Omschrijving",
)
st2 = StatusTranslationFactory(
trans_status_new_statustekst = StatusTranslationFactory(
status=self.status_type_new["statustekst"],
translation="Translated First Status Type Statustekst",
)
trans_status_finish_omschrijving = StatusTranslationFactory(
status=self.status_type_finish["omschrijving"],
translation="Translated Second Status Type",
)
self._setUpMocks(m)
response = self.app.get(
self.case_detail_url, user=self.user, headers={"HX-Request": "true"}
)
self.assertNotContains(response, st1.translation)
self.assertNotContains(response, st2.status)
self.assertContains(response, st2.translation)
self.assertNotContains(response, trans_status_new_omschrijving.translation)
self.assertNotContains(response, trans_status_new_omschrijving.status)

self.assertNotContains(response, trans_status_new_statustekst.status)
self.assertContains(response, trans_status_new_statustekst.translation)

self.assertNotContains(response, trans_status_finish_omschrijving.status)
self.assertContains(response, trans_status_finish_omschrijving.translation)

def test_when_accessing_case_detail_a_timelinelog_is_created(self, m):
self._setUpMocks(m)
Expand Down
8 changes: 7 additions & 1 deletion src/open_inwoner/utils/translate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from typing import Any

from glom import glom
Expand Down Expand Up @@ -37,3 +37,9 @@ def from_glom(self, obj: Any, path: str, *, default: str = "") -> str:
),
default=default,
)

def from_glom_multiple(
self, obj: Any, paths: Sequence, *, default: str = ""
) -> str:
gloms = (self.from_glom(obj, path, default=None) for path in paths)
return self(next((glom for glom in gloms if glom), default))

0 comments on commit 79c90b7

Please sign in to comment.