Refactor error messages.

When we didn't pass the redirect parameter in exceptions.handle() then
'_alert_message.html' template is used to displays the error messages.
If details are empty in a case but it still shows the 'Details' href
which is wrong and this patch adds a condition in that template to fix
that issue.

This patch also fix review comment of change-id
5081359295 and define a constant for
'\u2026' and use it in all files.

Note: '\u2026' is used for unicode glyph representing '...'.

Closes-Bug: #1893305

Partially-Implements blueprint refactor-error-messages

Change-Id: If4409a1245c983fb51712c6c817c11e884916694
Co-Author: Ivan Kolodyazhny <e0ne@e0ne.info>
This commit is contained in:
manchandavishal 2020-09-03 13:46:58 +00:00 committed by Radomir Dopieralski
parent 5943532672
commit 2f9014586f
5 changed files with 17 additions and 5 deletions

View File

@ -31,6 +31,8 @@ from horizon import messages
LOG = logging.getLogger(__name__)
SEPERATOR = '\u2026'
class HorizonReporterFilter(SafeExceptionReporterFilter):
"""Error report filter that's always active, even in DEBUG mode."""
@ -261,7 +263,7 @@ HANDLE_EXC_METHODS = [
def _append_detail(message, details):
return encoding.force_text(message) + '\u2026' + \
return encoding.force_text(message) + SEPERATOR + \
encoding.force_text(details)

View File

@ -49,6 +49,12 @@ horizon.alert = function (type, message, extra_tags, details) {
};
var this_alert = $(template.render(params)).hide().prependTo("#main_content .messages").fadeIn(100);
horizon.autoDismissAlert(this_alert);
// NOTE: messages template engine doesn't support conditional rendering yet
// So it's a temporary work-around to hide details link when details is empty.
if (details === undefined || details === "") {
this_alert.find("#details_link").remove();
}
return this_alert;
};

View File

@ -15,7 +15,8 @@
[[/safe]]
[[^safe]]
[[message]]
<a href="#message_details" data-toggle="collapse" data-target="#message_details">Details</a>
<a id="details_link" href="#message_details" data-toggle="collapse"
data-target="#message_details">Details</a>
<div id="message_details" class="collapse">
[[details]]
</div>

View File

@ -12,9 +12,11 @@
from django import template
from horizon import exceptions
register = template.Library()
@register.filter(name='split_message')
def split_message(value):
return value.split('\u2026')
return value.split(exceptions.SEPERATOR)

View File

@ -26,7 +26,8 @@ class HandleTests(test.TestCase):
# 'Because the container is not empty, it can not be deleted.'
expected = ['error', force_text(translated_unicode +
'\u2026' + translated_unicode), '']
exceptions.SEPERATOR +
translated_unicode), '']
req = self.request
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
@ -80,7 +81,7 @@ class HandleTests(test.TestCase):
message = u"Couldn't make the thing"
exc_msg = u"Exception string"
details = "custom detail message"
expected = ['error', message + '\u2026' + details, '']
expected = ['error', message + exceptions.SEPERATOR + details, '']
req = self.request
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'