Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2217] Use 'statustekst' as default case status label #1098

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -370,7 +369,8 @@ def handle_end_statustype_data(
if not status_types_mapping.get(end_statustype.url):
end_statustype_data = {
"label": status_translate(
end_statustype.omschrijving, default=_("No data available")
(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 @@ -541,8 +541,10 @@ def get_statuses_data(
return [
{
"date": s.datum_status_gezet,
"label": 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
6 changes: 4 additions & 2 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def process_data(self) -> dict:
"start_date": self.startdatum,
"end_date": getattr(self, "einddatum", None),
"description": self.zaaktype.omschrijving,
"current_status": 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
4 changes: 2 additions & 2 deletions src/open_inwoner/openzaak/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ def send_case_update_email(
"case_link": case_detail_url,
}
if status:
status_type = status.statustype
context["status_description"] = translate_single_status(
status.statustype.omschrijving
status_type.statustekst or status_type.omschrijving
)

if extra_context:
context.update(extra_context)
template.send_email([user.email], context)
Expand Down
28 changes: 18 additions & 10 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def setUp(self):
catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a",
omschrijving="Initial request",
omschrijvingGeneriek="some content",
statustekst="",
statustekst="Registered",
volgnummer=1,
isEindstatus=False,
)
Expand Down Expand Up @@ -735,7 +735,7 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(
"statuses": [
{
"date": datetime.datetime(2021, 1, 12),
"label": "Initial request",
"label": "Registered",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
Expand Down Expand Up @@ -858,7 +858,7 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"statuses": [
{
"date": datetime.datetime(2021, 1, 12),
"label": "Initial request",
"label": "Registered",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
Expand Down Expand Up @@ -1372,22 +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",
)
trans_status_new_statustekst = StatusTranslationFactory(
status=self.status_type_new["statustekst"],
translation="Translated First Status Type Statustekst",
)
st2 = StatusTranslationFactory(
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.status)
self.assertNotContains(response, st2.status)
self.assertContains(response, st1.translation)
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
40 changes: 21 additions & 19 deletions src/open_inwoner/openzaak/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,23 @@ def setUp(self):
vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar,
indicatieInternOfExtern="intern",
)
self.status_type1 = generate_oas_component_cached(
self.status_type_initial = generate_oas_component_cached(
"ztc",
"schemas/StatusType",
url=f"{CATALOGI_ROOT}statustypen/e3798107-ab27-4c3c-977d-777yu878km09",
zaaktype=self.zaaktype["url"],
omschrijving="Initial request",
statustekst="",
volgnummer=1,
isEindstatus=False,
)
self.status_type2 = generate_oas_component_cached(
self.status_type_finish = generate_oas_component_cached(
"ztc",
"schemas/StatusType",
url=f"{CATALOGI_ROOT}statustypen/e3798107-ab27-4c3c-977d-744516671fe4",
zaaktype=self.zaaktype["url"],
omschrijving="Finish",
statustekst="Statustekst finish",
volgnummer=2,
isEindstatus=True,
)
Expand All @@ -220,7 +222,7 @@ def setUp(self):
)
self.zt_statustype_config1 = ZaakTypeStatusTypeConfigFactory.create(
zaaktype_config=self.zaaktype_config1,
statustype_url=self.status_type1["url"],
statustype_url=self.status_type_initial["url"],
status_indicator=StatusIndicators.warning,
status_indicator_text="U moet documenten toevoegen",
description="Lorem ipsum dolor sit amet",
Expand All @@ -246,7 +248,7 @@ def setUp(self):
"schemas/Status",
url=self.zaak1["status"],
zaak=self.zaak1["url"],
statustype=self.status_type1["url"],
statustype=self.status_type_initial["url"],
datumStatusGezet="2021-01-12",
statustoelichting="",
)
Expand All @@ -268,7 +270,7 @@ def setUp(self):
"schemas/Status",
url=self.zaak2["status"],
zaak=self.zaak2["url"],
statustype=self.status_type1["url"],
statustype=self.status_type_initial["url"],
datumStatusGezet="2021-03-12",
statustoelichting="",
)
Expand Down Expand Up @@ -317,7 +319,7 @@ def setUp(self):
"schemas/Status",
url=self.zaak3["status"],
zaak=self.zaak3["url"],
statustype=self.status_type2["url"],
statustype=self.status_type_finish["url"],
datumStatusGezet="2021-03-15",
statustoelichting="",
)
Expand All @@ -340,7 +342,7 @@ def setUp(self):
"schemas/Status",
url=self.zaak_intern["status"],
zaak=self.zaak_intern["url"],
statustype=self.status_type1["url"],
statustype=self.status_type_initial["url"],
datumStatusGezet="2021-01-12",
statustoelichting="",
)
Expand Down Expand Up @@ -395,8 +397,8 @@ def _setUpMocks(self, m):
)
for resource in [
self.zaaktype,
self.status_type1,
self.status_type2,
self.status_type_initial,
self.status_type_finish,
self.status1,
self.status2,
self.status3,
Expand All @@ -414,7 +416,7 @@ def test_list_cases(self, m):
# led to errors when retrieving the ZaakTypeStatusTypeConfig. This duplicate
# config is added to verify that that issue was solved
ZaakTypeStatusTypeConfigFactory.create(
statustype_url=self.status_type1["url"],
statustype_url=self.status_type_initial["url"],
status_indicator=StatusIndicators.warning,
status_indicator_text="U moet documenten toevoegen",
description="Lorem ipsum dolor sit amet",
Expand All @@ -434,7 +436,7 @@ def test_list_cases(self, m):
"end_date": None,
"identification": self.zaak2["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand All @@ -445,7 +447,7 @@ def test_list_cases(self, m):
"end_date": None,
"identification": self.zaak1["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand All @@ -456,7 +458,7 @@ def test_list_cases(self, m):
"end_date": datetime.date.fromisoformat(self.zaak3["einddatum"]),
"identification": self.zaak3["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type2["omschrijving"],
"current_status": self.status_type_finish["statustekst"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": None,
"case_type": "Zaak",
Expand Down Expand Up @@ -515,7 +517,7 @@ def test_list_cases_for_eherkenning_user(self, m):
"end_date": None,
"identification": self.zaak_eherkenning2["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand All @@ -528,7 +530,7 @@ def test_list_cases_for_eherkenning_user(self, m):
"end_date": None,
"identification": self.zaak_eherkenning1["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand Down Expand Up @@ -596,7 +598,7 @@ def test_list_cases_for_eherkenning_user_with_vestigingsnummer(self, m):
"end_date": None,
"identification": self.zaak_eherkenning1["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand Down Expand Up @@ -715,7 +717,7 @@ def test_reformat_esuite_zaak_identificatie(self, m):

def test_list_cases_translates_status(self, m):
st1 = StatusTranslationFactory(
status=self.status_type1["omschrijving"],
status=self.status_type_initial["omschrijving"],
translation="Translated Status Type",
)
self._setUpMocks(m)
Expand Down Expand Up @@ -774,7 +776,7 @@ def test_list_cases_paginated(self, m):
"end_date": None,
"identification": self.zaak2["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand All @@ -797,7 +799,7 @@ def test_list_cases_paginated(self, m):
"end_date": None,
"identification": self.zaak1["identificatie"],
"description": self.zaaktype["omschrijving"],
"current_status": self.status_type1["omschrijving"],
"current_status": self.status_type_initial["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openzaak/tests/test_notification_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self):
informeren=True,
volgnummer=1,
omschrijving="initial",
statustekst="",
isEindStatus=False,
)
self.status_type_final = generate_oas_component_cached(
Expand All @@ -83,6 +84,7 @@ def __init__(self):
informeren=True,
volgnummer=2,
omschrijving="final",
statustekst="",
isEindStatus=True,
)
self.zaak = generate_oas_component_cached(
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
6 changes: 4 additions & 2 deletions src/open_inwoner/userfeed/hooks/case_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +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.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,
Expand Down Expand Up @@ -89,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('<span class="status">{}</span>', status_text)
html = format_html(html, status=status)
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
Loading