Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Imports 

2 

3from django.utils.translation import gettext_lazy as _ 

4from superdjango import ui 

5from .models import Category, Notification, NotificationUser, UserPreferences 

6 

7# Exports 

8 

9__all__ = ( 

10 "CategoryUI", 

11 "NotificationUI", 

12 "NotificationsMenu", 

13 "NotificationUserUI", 

14) 

15 

16# Models 

17 

18 

19class CategoryUI(ui.ModelUI): 

20 """A user interface for notification category lookups.""" 

21 model = Category 

22 

23 controls = { 

24 'is_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 

25 'value': ui.controls.SlugControl(from_field="label"), 

26 } 

27 

28 detail_options = ui.DetailOptions( 

29 "label", 

30 "value", 

31 "abbr", 

32 "description", 

33 "is_enabled", 

34 ) 

35 form_options = ui.ModelFormOptions( 

36 "label", 

37 "value", 

38 "abbr", 

39 "description", 

40 "is_enabled", 

41 ) 

42 list_options = ui.ListOptions( 

43 "label", 

44 "abbr", 

45 "is_enabled", 

46 filtering=ui.Filtering("is_enabled"), 

47 link_field="label" 

48 ) 

49 

50 

51class NotificationUI(ui.ModelUI): 

52 """A user interface for user notifications.""" 

53 model = Notification 

54 

55 controls = { 

56 'email_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 

57 'html_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 

58 'is_mandatory': ui.controls.BooleanControl(align="center", css_icon=True), 

59 'is_promoted': ui.controls.BooleanControl(align="center", css_icon=True), 

60 'sms_enabled': ui.controls.BooleanControl(align="center", css_icon=True), 

61 } 

62 

63 detail_options = ui.DetailOptions( 

64 "subject", 

65 "added_dt", 

66 "category", 

67 "body", 

68 "body_sms", 

69 "level", 

70 "icon_override", 

71 "users", 

72 "is_mandatory", 

73 "is_promoted", 

74 "html_enabled", 

75 "email_enabled", 

76 "sms_enabled", 

77 "stage", 

78 "has_been_sent", 

79 "sent_dt", 

80 "action_url", 

81 "action_text", 

82 ) 

83 form_options = ui.ModelFormOptions( 

84 "subject", 

85 "category", 

86 "body", 

87 "body_sms", 

88 "level", 

89 "icon_override", 

90 "users", 

91 "is_mandatory", 

92 "is_promoted", 

93 "html_enabled", 

94 "email_enabled", 

95 "sms_enabled", 

96 "action_url", 

97 "action_text", 

98 ) 

99 list_options = ui.ListOptions( 

100 "subject", 

101 "added_dt", 

102 "category", 

103 "level", 

104 "users" 

105 "is_mandatory", 

106 "is_promoted", 

107 "html_enabled", 

108 "email_enabled", 

109 "sms_enabled", 

110 "stage", 

111 "has_been_sent", 

112 "sent_dt", 

113 filtering=ui.Filtering( 

114 "category", 

115 "level", 

116 "is_mandatory", 

117 "is_promoted", 

118 "stage", 

119 ), 

120 link_field="subject" 

121 ) 

122 

123 

124class NotificationUserUI(ui.ModelUI): 

125 """User interface for the user notification log.""" 

126 model = NotificationUser 

127 

128 controls = { 

129 'has_been_viewed': ui.controls.BooleanControl(align="center", css_icon=True), 

130 'sent_email': ui.controls.BooleanControl(align="center", css_icon=True), 

131 'sent_sms': ui.controls.BooleanControl(align="center", css_icon=True), 

132 } 

133 

134 detail_options = ui.DetailOptions( 

135 "notification", 

136 "user", 

137 "has_been_viewed", 

138 "viewed_dt", 

139 "sent_email", 

140 "sent_sms", 

141 ) 

142 list_options = ui.ListOptions( 

143 "notification", 

144 "user", 

145 "has_been_viewed", 

146 "viewed_dt", 

147 "sent_email", 

148 "sent_sms", 

149 filtering=ui.Filtering( 

150 "has_been_viewed", 

151 "user", 

152 "sent_email", 

153 "sent_sms" 

154 ), 

155 record_actions=[ui.VERB.DETAIL, ui.VERB.DELETE] 

156 ) 

157 

158# Menus 

159 

160 

161class NotificationsMenu(ui.Menu): 

162 icon = "fas fa-comment-alt" 

163 items = [ 

164 NotificationUI, 

165 NotificationUserUI, 

166 ui.MenuSeparator(), 

167 CategoryUI, 

168 ] 

169 label = _("Notifications") 

170 prefix = "notifications"