diff --git a/allianceauth/notifications/__init__.py b/allianceauth/notifications/__init__.py index 6e044162..e22e6ad7 100644 --- a/allianceauth/notifications/__init__.py +++ b/allianceauth/notifications/__init__.py @@ -1,9 +1,3 @@ +from .core import notify # noqa: F401 + default_app_config = 'allianceauth.notifications.apps.NotificationsConfig' - - -def notify( - user: object, title: str, message: str = None, level: str = 'info' -) -> None: - """Sends a new notification to user. Convenience function to manager pendant.""" - from .models import Notification - Notification.objects.notify_user(user, title, message, level) diff --git a/allianceauth/notifications/core.py b/allianceauth/notifications/core.py new file mode 100644 index 00000000..b750ba4d --- /dev/null +++ b/allianceauth/notifications/core.py @@ -0,0 +1,33 @@ +class NotifyApiWrapper: + """Wrapper to create notify API.""" + + def __call__(self, *args, **kwargs): # provide old API for backwards compatibility + return self._add_notification(*args, **kwargs) + + def danger(self, user: object, title: str, message: str = None) -> None: + """Add danger notification for user.""" + self._add_notification(user, title, message, level="danger") + + def info(self, user: object, title: str, message: str = None) -> None: + """Add info notification for user.""" + self._add_notification(user=user, title=title, message=message, level="info") + + def success(self, user: object, title: str, message: str = None) -> None: + """Add success notification for user.""" + self._add_notification(user, title, message, level="success") + + def warning(self, user: object, title: str, message: str = None) -> None: + """Add warning notification for user.""" + self._add_notification(user, title, message, level="warning") + + def _add_notification( + self, user: object, title: str, message: str = None, level: str = "info" + ) -> None: + from .models import Notification + + Notification.objects.notify_user( + user=user, title=title, message=message, level=level + ) + + +notify = NotifyApiWrapper() diff --git a/allianceauth/notifications/templates/notifications/list.html b/allianceauth/notifications/templates/notifications/list.html index f940bac1..1e332ad4 100644 --- a/allianceauth/notifications/templates/notifications/list.html +++ b/allianceauth/notifications/templates/notifications/list.html @@ -5,91 +5,34 @@ {% block page_title %}{% translate "Notifications" %}{% endblock %} {% block content %} -
{% translate "Timestamp" %} | +{% translate "Title" %} | +{% translate "Action" %} | +
---|---|---|
{{ notif.timestamp }} | +{{ notif.title }} | ++ + + + + + + | +
{{ notif.message }}
{{ notif.message }}