Skip to content

Commit

Permalink
Handle safe strings in bootstrap_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jul 13, 2021
1 parent 1138185 commit c7dbd6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load django_bootstrap5 %}
{% for message in messages %}
{% bootstrap_alert message|default:"" alert_type=message|bootstrap_message_alert_type extra_classes=message.extra_tags %}
{% bootstrap_alert message.message|default:"" alert_type=message|bootstrap_message_alert_type extra_classes=message.extra_tags %}
{% endfor %}
10 changes: 10 additions & 0 deletions tests/test_bootstrap_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.messages import constants as DEFAULT_MESSAGE_LEVELS
from django.contrib.messages.storage.base import Message
from django.utils.safestring import mark_safe

from tests.base import BootstrapTestCase

Expand Down Expand Up @@ -51,6 +52,15 @@ def test_bootstrap_messages_with_other_content(self):
self._html(content="hello there", css_class="alert-danger"),
)

def test_bootstrap_messages_with_safe_message(self):
messages = [Message(DEFAULT_MESSAGE_LEVELS.INFO, mark_safe("Click <a href='https://www.github.com/'>here</a>"))]
html = self.render("{% bootstrap_messages messages %}", {"messages": messages})
print(html)
self.assertHTMLEqual(
self.render("{% bootstrap_messages messages %}", {"messages": messages}),
self._html(content="Click <a href='https://www.github.com/'>here</a>", css_class="alert-info"),
)

def test_bootstrap_messages_with_invalid_message(self):
messages = [None]
self.assertHTMLEqual(
Expand Down

0 comments on commit c7dbd6e

Please sign in to comment.