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 21, 2024
1 parent 3c61d5e commit 3f7aa26
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 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
10 changes: 4 additions & 6 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions src/open_inwoner/openzaak/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
4 changes: 3 additions & 1 deletion src/open_inwoner/openzaak/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/open_inwoner/userfeed/hooks/case_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": (
status.statustype.statustekst or status.statustype.omschrijving
),
# new for actionable
"catalogus_url": case.zaaktype.catalogus,
"case_type_identificatie": case.zaaktype.identificatie,
Expand Down
11 changes: 10 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,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

0 comments on commit 3f7aa26

Please sign in to comment.