From faa230254c1974444b3c0028ee4349f68e610052 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 6 Nov 2023 16:40:19 +0100 Subject: [PATCH 1/3] :sparkles: [#1797] Show filename(s) in success msg for document upload task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1797 --- src/open_inwoner/cms/cases/views/status.py | 16 +++++++++++++--- .../components/Notification/Notification.html | 8 ++++++-- .../components/Notification/Notifications.html | 6 ++++-- .../components/templatetags/string_tags.py | 9 +++++++++ .../components/Notification/_Notification.scss | 8 ++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index ffbe665b89..8b5113a3e7 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -477,12 +477,22 @@ def handle_document_upload(self, request, form): filename=file.name, ), ) + + # TODO implement `created_documents` properly when uploading of multiple + # docs is implemented + created_documents = [created_document] + success_message = ( + _( + "Wij hebben **{num_uploaded} bestand(en)** succesvol geüpload:" + ).format(num_uploaded=len(created_documents)) + + "\n\n" + + "\n".join(f"- {doc['titel']}" for doc in created_documents) + ) messages.add_message( request, messages.SUCCESS, - _("{filename} has been successfully uploaded").format( - filename=file.name - ), + success_message, + extra_tags="as_markdown", ) return HttpResponseClientRedirect( diff --git a/src/open_inwoner/components/templates/components/Notification/Notification.html b/src/open_inwoner/components/templates/components/Notification/Notification.html index b6c7f87ad1..049d3ab264 100644 --- a/src/open_inwoner/components/templates/components/Notification/Notification.html +++ b/src/open_inwoner/components/templates/components/Notification/Notification.html @@ -1,4 +1,4 @@ -{% load i18n button_tags icon_tags button_tags icon_tags %} +{% load i18n ssd_tags button_tags icon_tags button_tags icon_tags %}
{% if not icon == False %}
@@ -13,7 +13,11 @@ {% if contents %} {{ contents }} {% else %} -

{{ message }}

+ {% if as_markdown %} + {{ message|markdown|safe }} + {% else %} +

{{ message }}

+ {% endif %} {% endif %}
diff --git a/src/open_inwoner/components/templates/components/Notification/Notifications.html b/src/open_inwoner/components/templates/components/Notification/Notifications.html index 6b1f69d055..df7a645b63 100644 --- a/src/open_inwoner/components/templates/components/Notification/Notifications.html +++ b/src/open_inwoner/components/templates/components/Notification/Notifications.html @@ -1,7 +1,9 @@ -{% load notification_tags %} +{% load notification_tags string_tags %}
{% for message in messages %} - {% notification icon=message.icon type=message.level_tag message=message.message closable=True compact=compact %} + {% with as_markdown=message.extra_tags|is_substring:"as_markdown" %} + {% notification icon=message.icon type=message.level_tag message=message.message as_markdown=as_markdown closable=True compact=compact %} + {% endwith %} {% endfor %}
diff --git a/src/open_inwoner/components/templatetags/string_tags.py b/src/open_inwoner/components/templatetags/string_tags.py index 8a9b9f413d..8d79d0e66f 100644 --- a/src/open_inwoner/components/templatetags/string_tags.py +++ b/src/open_inwoner/components/templatetags/string_tags.py @@ -29,3 +29,12 @@ def optional_paragraph(optional_text: str) -> str: optional_text=linebreaksbr(optional_text) ) ) + + +@register.filter +def is_substring(arg1, arg2): + """check if arg2 is a substring of arg1""" + if not arg1: + return False + + return arg2 in arg1 diff --git a/src/open_inwoner/scss/components/Notification/_Notification.scss b/src/open_inwoner/scss/components/Notification/_Notification.scss index b492c42f74..5377c309aa 100644 --- a/src/open_inwoner/scss/components/Notification/_Notification.scss +++ b/src/open_inwoner/scss/components/Notification/_Notification.scss @@ -92,4 +92,12 @@ position: inherit; } } + + & &__content { + margin-top: 0.15em; + + & * { + margin: 0; + } + } } From 7787d08f3a2eba8bc8674f17ae39cd23be72db44 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 9 Nov 2023 10:23:02 +0100 Subject: [PATCH 2/3] :sparkles: [#1797] Move document upload success msg to above form task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1797 --- src/open_inwoner/cms/cases/views/status.py | 2 +- .../templates/components/Notification/Notifications.html | 6 +++++- src/open_inwoner/templates/pages/cases/status_inner.html | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 8b5113a3e7..2771ab011a 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -492,7 +492,7 @@ def handle_document_upload(self, request, form): request, messages.SUCCESS, success_message, - extra_tags="as_markdown", + extra_tags="as_markdown local_message", ) return HttpResponseClientRedirect( diff --git a/src/open_inwoner/components/templates/components/Notification/Notifications.html b/src/open_inwoner/components/templates/components/Notification/Notifications.html index df7a645b63..4a6252f487 100644 --- a/src/open_inwoner/components/templates/components/Notification/Notifications.html +++ b/src/open_inwoner/components/templates/components/Notification/Notifications.html @@ -3,7 +3,11 @@
{% for message in messages %} {% with as_markdown=message.extra_tags|is_substring:"as_markdown" %} - {% notification icon=message.icon type=message.level_tag message=message.message as_markdown=as_markdown closable=True compact=compact %} + {% with local_message=message.extra_tags|is_substring:"local_message" %} + {% if show_local_messages and local_message or not show_local_messages and not local_message %} + {% notification icon=message.icon type=message.level_tag message=message.message as_markdown=as_markdown closable=True compact=compact %} + {% endif %} + {% endwith %} {% endwith %} {% endfor %}
diff --git a/src/open_inwoner/templates/pages/cases/status_inner.html b/src/open_inwoner/templates/pages/cases/status_inner.html index c33236cf5a..cbeafdf71e 100644 --- a/src/open_inwoner/templates/pages/cases/status_inner.html +++ b/src/open_inwoner/templates/pages/cases/status_inner.html @@ -31,6 +31,8 @@

{% trans 'Documenten' %}

{% if case.internal_upload_enabled %}

{% trans "Document uploaden" %}

+ {% notifications messages show_local_messages=True %} + {% if case.case_type_document_upload_description %}
From 136638f8463672190dcb9e29097833ef5f946375 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 9 Nov 2023 11:30:20 +0100 Subject: [PATCH 3/3] :white_check_mark: [#1797] Fix tests for document upload success msg task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1797 --- .../openzaak/tests/test_case_detail.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index df778253b3..6709206315 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -275,6 +275,7 @@ def setUpTestData(cls): vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar, bestandsnaam="upload.txt", bestandsomvang=123, + titel="uploaded file", ) cls.zaak_informatie_object_invisible = generate_oas_component( @@ -905,8 +906,8 @@ def test_successful_document_upload_flow(self, m): self.assertEqual( redirect_messages[0].message, - _( - f"{self.uploaded_informatie_object['bestandsnaam']} is succesvol geüpload" + _("Wij hebben **1 bestand(en)** succesvol geüpload:\n\n- {title}").format( + title="uploaded file" ), ) @@ -942,10 +943,18 @@ def test_successful_document_upload_flow_with_uppercase_extension(self, m): redirect = self.app.get(form_response.headers["HX-Redirect"]) redirect_messages = list(redirect.context["messages"]) + upload_request = next( + request + for request in m.request_history + if request.url == f"{DOCUMENTEN_ROOT}enkelvoudiginformatieobjecten" + ) + self.assertEqual(upload_request.json()["bestandsnaam"], "upload.TXT") self.assertEqual( redirect_messages[0].message, - _("upload.TXT is succesvol geüpload"), + _("Wij hebben **1 bestand(en)** succesvol geüpload:\n\n- {title}").format( + title="uploaded file" + ), ) def test_upload_file_flow_fails_with_invalid_file_extension(self, m):