Browse Source

Merge "Refactor error messages."

tags/18.6.0
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
d9bf46371e
5 changed files with 17 additions and 5 deletions
  1. +3
    -1
      horizon/exceptions.py
  2. +6
    -0
      horizon/static/horizon/js/horizon.messages.js
  3. +2
    -1
      horizon/templates/horizon/client_side/_alert_message.html
  4. +3
    -1
      horizon/templatetags/splitfilter.py
  5. +3
    -2
      horizon/test/unit/test_exceptions.py

+ 3
- 1
horizon/exceptions.py 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)




+ 6
- 0
horizon/static/horizon/js/horizon.messages.js 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;
};



+ 2
- 1
horizon/templates/horizon/client_side/_alert_message.html 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>


+ 3
- 1
horizon/templatetags/splitfilter.py 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)

+ 3
- 2
horizon/test/unit/test_exceptions.py 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'



Loading…
Cancel
Save