Skip to content

Commit

Permalink
[#2912] Fix styling for zgw import-export error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Nov 28, 2024
1 parent e589b3a commit 88a6f4b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
10 changes: 4 additions & 6 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,13 @@ def process_file_view(self, request):
error_msg_iterator = ([msg] for msg in msgs_deduped)

error_msg_html = format_html_join(
"\n", "<li>{}</li>", error_msg_iterator
"\n", "<p> - {}</p>", error_msg_iterator
)
error_msg_html_ordered = format_html(
error_msg_html = format_html(
_("It was not possible to import the following items:")
+ f"<ol> {error_msg_html} </ol>"
)
self.message_user(
request, error_msg_html_ordered, messages.ERROR
+ f"<div>{error_msg_html}</div>"
)
self.message_user(request, error_msg_html, messages.ERROR)

return HttpResponseRedirect(
reverse(
Expand Down
18 changes: 9 additions & 9 deletions src/open_inwoner/openzaak/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ def extract_error_data(cls, exc: Exception, jsonl: str):
fields = data.get("fields", None)
if source_config is CatalogusConfig:
items = [
f"Domein = {fields['domein']}",
f"Rsin = {fields['rsin']}",
f"Domein = {fields['domein']!r}",
f"Rsin = {fields['rsin']!r}",
]
if source_config is ZaakTypeConfig:
items = [
f"Identificatie = {fields['identificatie']}",
f"Catalogus domein = {fields['catalogus'][0]}",
f"Catalogus rsin = {fields['catalogus'][1]}",
f"Identificatie = {fields['identificatie']!r}",
f"Catalogus domein = {fields['catalogus'][0]!r}",
f"Catalogus rsin = {fields['catalogus'][1]!r}",
]
if source_config in {
ZaakTypeStatusTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
}:
items = [
f"omschrijving = {fields['omschrijving']}",
f"ZaakTypeConfig identificatie = {fields['zaaktype_config'][0]}",
f"Catalogus domein = {fields['zaaktype_config'][1]}",
f"Catalogus rsin = {fields['zaaktype_config'][2]}",
f"omschrijving = {fields['omschrijving']!r}",
f"ZaakTypeConfig identificatie = {fields['zaaktype_config'][0]!r}",
f"Catalogus domein = {fields['zaaktype_config'][1]!r}",
f"Catalogus rsin = {fields['zaaktype_config'][2]!r}",
]

return {
Expand Down
29 changes: 15 additions & 14 deletions src/open_inwoner/openzaak/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import html
import json
from unittest import mock

Expand Down Expand Up @@ -280,39 +281,39 @@ def test_import_flow_reports_errors(self) -> None:

response = form.submit().follow()

messages = [str(msg) for msg in response.context["messages"]]
messages = [html.unescape(str(msg)) for msg in response.context["messages"]]
self.assertEqual(len(messages), 2)
self.assertEqual(
_("6 item(s) processed in total, with 6 failing row(s)."),
messages[0],
)
self.assertIn(
"ZaakTypeConfig not found in target environment: Identificatie = ztc-id-a-0, "
"Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeConfig not found in target environment: Identificatie = 'ztc-id-a-0', "
"Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = status omschrijving, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'status omschrijving', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = bogus, ZaakTypeConfig "
"identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'bogus', ZaakTypeConfig "
"identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeInformatieObjectTypeConfig not found in target environment: omschrijving = informatieobject, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeInformatieObjectTypeConfig not found in target environment: omschrijving = 'informatieobject', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"CatalogusConfig not found in target environment: Domein = DM-0, Rsin = 123456789",
"CatalogusConfig not found in target environment: Domein = 'DM-0', Rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeResultaatTypeConfig not found in target environment: omschrijving = resultaat, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeResultaatTypeConfig not found in target environment: omschrijving = 'resultaat', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)

Expand Down Expand Up @@ -341,13 +342,13 @@ def test_import_flow_reports_partial_errors(self) -> None:

response = form.submit().follow()

messages = [str(msg) for msg in response.context["messages"]]
messages = [html.unescape(str(msg)) for msg in response.context["messages"]]
self.assertEqual(len(messages), 2)
self.assertEqual(
_("2 item(s) processed in total, with 1 failing row(s)."),
messages[0],
)
self.assertEqual(
"It was not possible to import the following items:<ol> <li>ZaakTypeConfig not found in target environment: Identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789</li> </ol>",
"It was not possible to import the following items:<div><p> - ZaakTypeConfig not found in target environment: Identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'</p></div>",
messages[1],
)

0 comments on commit 88a6f4b

Please sign in to comment.