from django import template
from django.contrib.messages import constants as message_constants


MESSAGE_LEVEL_TYPES = {
    message_constants.DEBUG: "info",
    message_constants.INFO: "info",
    message_constants.SUCCESS: "success",
    message_constants.WARNING: "notice",
    message_constants.ERROR: "error",
}


register = template.Library()


@register.filter
def pnotify_type(message):
    try:
        level = message.level
    except AttributeError:
        return 'info'
    else:
        try:
            return MESSAGE_LEVEL_TYPES[level]
        except KeyError:
            return "info"
