From cc9c7413ac8f014c9e277932ab48359695684487 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 25 Oct 2018 10:28:57 +0200 Subject: [PATCH] Simplification of message tag resolution and setting, fixes #922 --- src/wiki/conf/settings.py | 12 ++++++------ src/wiki/templatetags/wiki_tags.py | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/wiki/conf/settings.py b/src/wiki/conf/settings.py index c558bf7f..ff2aae83 100644 --- a/src/wiki/conf/settings.py +++ b/src/wiki/conf/settings.py @@ -160,16 +160,16 @@ LOG_IPS_ANONYMOUS = getattr(django_settings, 'WIKI_LOG_IPS_ANONYMOUS', True) #: Do we want to log IPs of logged in users? LOG_IPS_USERS = getattr(django_settings, 'WIKI_LOG_IPS_USERS', False) -#: Mapping from message.tag to bootstrap class names. +#: Mapping from message.level to bootstrap class names. MESSAGE_TAG_CSS_CLASS = getattr( django_settings, 'WIKI_MESSAGE_TAG_CSS_CLASS', { - messages.DEFAULT_TAGS[messages.DEBUG]: "alert alert-info", - messages.DEFAULT_TAGS[messages.ERROR]: "alert alert-danger", - messages.DEFAULT_TAGS[messages.INFO]: "alert alert-info", - messages.DEFAULT_TAGS[messages.SUCCESS]: "alert alert-success", - messages.DEFAULT_TAGS[messages.WARNING]: "alert alert-warning", + messages.DEBUG: "alert alert-info", + messages.ERROR: "alert alert-danger", + messages.INFO: "alert alert-info", + messages.SUCCESS: "alert alert-success", + messages.WARNING: "alert alert-warning", } ) diff --git a/src/wiki/templatetags/wiki_tags.py b/src/wiki/templatetags/wiki_tags.py index 560f1355..94030364 100644 --- a/src/wiki/templatetags/wiki_tags.py +++ b/src/wiki/templatetags/wiki_tags.py @@ -80,11 +80,7 @@ def wiki_messages(context): messages = context.get('messages', []) for message in messages: - message.css_class = "" - for tag in message.tags.split(" "): - # Drop KeyError if MESSAGE_TAG_CSS_CLASS doesn't have the tag, - # that seems valuable. - message.css_class += " " + settings.MESSAGE_TAG_CSS_CLASS[tag] + message.css_class = settings.MESSAGE_TAG_CSS_CLASS[message.level] context.update({ 'messages': messages }) -- 2.45.2