Source code for superdjango.contrib.notifications.ui

# Imports

from django.utils.translation import gettext_lazy as _
from superdjango import ui
from .models import Category, Notification, NotificationUser, UserPreferences

# Exports

__all__ = (
    "CategoryUI",
    "NotificationUI",
    "NotificationsMenu",
    "NotificationUserUI",
)

# Models


[docs]class CategoryUI(ui.ModelUI): """A user interface for notification category lookups.""" model = Category controls = { 'is_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 'value': ui.controls.SlugControl(from_field="label"), } detail_options = ui.DetailOptions( "label", "value", "abbr", "description", "is_enabled", ) form_options = ui.ModelFormOptions( "label", "value", "abbr", "description", "is_enabled", ) list_options = ui.ListOptions( "label", "abbr", "is_enabled", filtering=ui.Filtering("is_enabled"), link_field="label" )
[docs]class NotificationUI(ui.ModelUI): """A user interface for user notifications.""" model = Notification controls = { 'email_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 'html_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 'is_mandatory': ui.controls.BooleanControl(align="center", css_icon=True), 'is_promoted': ui.controls.BooleanControl(align="center", css_icon=True), 'sms_enabled': ui.controls.BooleanControl(align="center", css_icon=True), } detail_options = ui.DetailOptions( "subject", "added_dt", "category", "body", "body_sms", "level", "icon_override", "users", "is_mandatory", "is_promoted", "html_enabled", "email_enabled", "sms_enabled", "stage", "has_been_sent", "sent_dt", "action_url", "action_text", ) form_options = ui.ModelFormOptions( "subject", "category", "body", "body_sms", "level", "icon_override", "users", "is_mandatory", "is_promoted", "html_enabled", "email_enabled", "sms_enabled", "action_url", "action_text", ) list_options = ui.ListOptions( "subject", "added_dt", "category", "level", "users" "is_mandatory", "is_promoted", "html_enabled", "email_enabled", "sms_enabled", "stage", "has_been_sent", "sent_dt", filtering=ui.Filtering( "category", "level", "is_mandatory", "is_promoted", "stage", ), link_field="subject" )
[docs]class NotificationUserUI(ui.ModelUI): """User interface for the user notification log.""" model = NotificationUser controls = { 'has_been_viewed': ui.controls.BooleanControl(align="center", css_icon=True), 'sent_email': ui.controls.BooleanControl(align="center", css_icon=True), 'sent_sms': ui.controls.BooleanControl(align="center", css_icon=True), } detail_options = ui.DetailOptions( "notification", "user", "has_been_viewed", "viewed_dt", "sent_email", "sent_sms", ) list_options = ui.ListOptions( "notification", "user", "has_been_viewed", "viewed_dt", "sent_email", "sent_sms", filtering=ui.Filtering( "has_been_viewed", "user", "sent_email", "sent_sms" ), record_actions=[ui.VERB.DETAIL, ui.VERB.DELETE] )
# Menus
[docs]class NotificationsMenu(ui.Menu): icon = "fas fa-comment-alt" items = [ NotificationUI, NotificationUserUI, ui.MenuSeparator(), CategoryUI, ] label = _("Notifications") prefix = "notifications"