~netlandish/django-wiki

cc9c7413ac8f014c9e277932ab48359695684487 — Benjamin Bach 6 years ago 85474a6
Simplification of message tag resolution and setting, fixes #922
2 files changed, 7 insertions(+), 11 deletions(-)

M src/wiki/conf/settings.py
M src/wiki/templatetags/wiki_tags.py
M src/wiki/conf/settings.py => src/wiki/conf/settings.py +6 -6
@@ 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",
    }
)


M src/wiki/templatetags/wiki_tags.py => src/wiki/templatetags/wiki_tags.py +1 -5
@@ 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
    })