Source code for espressodb.notifications.templatetags.notifications_extras

"""Additional in template functions for the notifications module.
"""
from typing import Dict, Any

from django import template
from django.contrib.auth.models import User

from espressodb.notifications.models import Notification
from espressodb.notifications.models import LEVELS

register = template.Library()  # pylint: disable=C0103


[docs]@register.inclusion_tag("render_notification.html") def render_notification( notification: Notification, hide_close: bool = False ) -> Dict[str, Any]: """Renders notifications Arguments: notification: The notification. hide_close: Hide the has read button in view for this notfication. Uses template ``espressodb/notfications/templates/render_notification.html``. """ context = {"notification": notification, "hide_close": hide_close} return context
[docs]@register.simple_tag def bootstrap_level(level: str) -> str: """Maps logging levels to bootstrap levels. Defaults to light. Arguments: level: The logging level. """ return { "DEBUG": "secondary", "INFO": "info", "WARNING": "warning", "ERROR": "danger", }.get(level.upper(), "light")