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

✨ [#1797] Show filename(s) in success msg for document upload #837

Merged
merged 3 commits into from
Nov 10, 2023
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
16 changes: 13 additions & 3 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 local_message",
)

return HttpResponseClientRedirect(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="notification{% if contents %} notification--contents{% endif %}{% if type %} notification--{{ type }}{% endif %}{% if compact %} notification--compact{% endif %} {% if ctx %}notification--{{ ctx }}{% endif %}">
{% if not icon == False %}
<div class="notification__icon">
Expand All @@ -13,7 +13,11 @@
{% if contents %}
{{ contents }}
{% else %}
<p class="p p--compact">{{ message }}</p>
{% if as_markdown %}
{{ message|markdown|safe }}
{% else %}
<p class="p p--compact">{{ message }}</p>
{% endif %}
{% endif %}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{% load notification_tags %}
{% load notification_tags string_tags %}

<div class="notifications">
{% 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" %}
{% with local_message=message.extra_tags|is_substring:"local_message" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra_tags|has_as_substring:"as_markdown" would read more natural imho (similarly for the signature of the tag).

{% 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 %}
</div>
9 changes: 9 additions & 0 deletions src/open_inwoner/components/templatetags/string_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
),
)

Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@
position: inherit;
}
}

& &__content {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it usual to have block and element as part of the same class? I'm familiar with block__element block__element--modifier but haven't seen block block__element before. Or perhaps I misunderstand the & & syntax.

margin-top: 0.15em;

& * {
margin: 0;
}
}
}
2 changes: 2 additions & 0 deletions src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ <h2 class="h2" id="documents">{% trans 'Documenten' %}</h2>
{% if case.internal_upload_enabled %}
<h2 class="h2" id="documents-upload">{% trans "Document uploaden" %}</h2>

{% notifications messages show_local_messages=True %}

{% if case.case_type_document_upload_description %}
<div class="card card--compact card--info">
<div class="card__body document-upload-description">
Expand Down
Loading