diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index fd1b9dd6f5..a19043f6ac 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -214,7 +214,6 @@ def get_context_data(self, **kwargs): "statuses": self.get_statuses_data( statuses, status_translate, self.statustype_config_mapping ), - # "end_statustype_data": end_statustype_data, "end_statustype_data": end_statustype_data, "second_status_preview": second_status_preview, "documents": documents, @@ -369,11 +368,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), @@ -544,11 +541,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), diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index 8a0da498c7..b4ecb20fb7 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -5,7 +5,6 @@ from typing import Optional, Union from dateutil.relativedelta import relativedelta -from glom import glom from zgw_consumers.api_models.base import Model, ZGWModel from zgw_consumers.api_models.constants import RolOmschrijving, RolTypes @@ -80,11 +79,10 @@ def process_data(self) -> dict: "start_date": self.startdatum, "end_date": getattr(self, "einddatum", None), "description": self.zaaktype.omschrijving, - "current_status": ( - glom(self, "status.statustype.statustekst") - or status_translate.from_glom( - self, "status.statustype.omschrijving", default="" - ) + "current_status": status_translate.from_glom_multiple( + self, + ("status.statustype.statustekst", "status.statustype.omschrijving"), + default="", ), "zaaktype_config": getattr(self, "zaaktype_config", None), "statustype_config": getattr(self, "statustype_config", None), diff --git a/src/open_inwoner/openzaak/notifications.py b/src/open_inwoner/openzaak/notifications.py index fa49a3e637..7f097f3c27 100644 --- a/src/open_inwoner/openzaak/notifications.py +++ b/src/open_inwoner/openzaak/notifications.py @@ -591,10 +591,9 @@ def send_case_update_email( "case_link": case_detail_url, } if status: - context[ - "status_description" - ] = status.statustype.statustekst or translate_single_status( - status.statustype.omschrijving + status_type = status.statustype + context["status_description"] = translate_single_status( + status_type.statustekst or status_type.omschrijving ) if extra_context: context.update(extra_context) diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index b77df7cf71..207af3b8e1 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -1372,11 +1372,15 @@ 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", ) @@ -1384,9 +1388,14 @@ def test_page_translates_statuses(self, 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) diff --git a/src/open_inwoner/openzaak/utils.py b/src/open_inwoner/openzaak/utils.py index c8d4b4ce62..699e86bc6a 100644 --- a/src/open_inwoner/openzaak/utils.py +++ b/src/open_inwoner/openzaak/utils.py @@ -1,5 +1,7 @@ import logging +from django.utils.translation import gettext as _ + from zgw_consumers.api_models.constants import RolTypes, VertrouwelijkheidsAanduidingen from open_inwoner.kvk.branches import get_kvk_branch_number @@ -133,7 +135,7 @@ def get_zaak_type_info_object_type_config( def translate_single_status(status_text: str) -> str: if not status_text: - return "" + return _("No data available") # in most cases try to cache with StatusTranslation.objects.get_lookup() try: diff --git a/src/open_inwoner/userfeed/hooks/case_status.py b/src/open_inwoner/userfeed/hooks/case_status.py index ec4ad3e769..1d60b6564d 100644 --- a/src/open_inwoner/userfeed/hooks/case_status.py +++ b/src/open_inwoner/userfeed/hooks/case_status.py @@ -23,8 +23,9 @@ def case_status_notification_received(user: User, case: Zaak, status: Status): "case_uuid": case.uuid, "case_identificatie": case.identificatie, "case_omschrijving": case.omschrijving, - "status_omschrijving": status.statustype.statustekst - or status.statustype.omschrijving, + "status_omschrijving": translate_single_status( + status.statustype.statustekst or status.statustype.omschrijving + ), # new for actionable "catalogus_url": case.zaaktype.catalogus, "case_type_identificatie": case.zaaktype.identificatie, @@ -90,7 +91,7 @@ def title(self) -> str: @property def message(self) -> str: status_text = self.get_data("status_omschrijving") - status_text = translate_single_status(status_text) or _("onbekend") + status_text = translate_single_status(status_text) html = escape(self.base_message) status = format_html('{}', status_text) html = format_html(html, status=status) diff --git a/src/open_inwoner/utils/translate.py b/src/open_inwoner/utils/translate.py index 058c966b0b..001719a3ea 100644 --- a/src/open_inwoner/utils/translate.py +++ b/src/open_inwoner/utils/translate.py @@ -1,4 +1,4 @@ -from collections.abc import Iterable +from collections.abc import Iterable, Sequence from typing import Any from glom import glom @@ -37,3 +37,12 @@ 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: + for p in paths: + value = self.from_glom(obj, p, default=None) + if value: + return self(value) + return default