47
47
from .models import Broadcast , Label , LabelCount , Media , MessageExport , Msg , OptIn , SystemLabel
48
48
49
49
50
- class SystemLabelView ( SpaMixin , BaseListView ):
50
+ class MsgListView ( ContextMenuMixin , BulkActionMixin , SpaMixin , BaseListView ):
51
51
"""
52
- Base class for views backed by a system label or message label queryset
52
+ Base class for message list views with message folders and labels listed by the side
53
53
"""
54
54
55
+ permission = "msgs.msg_list"
56
+ search_fields = ("text__icontains" , "contact__name__icontains" , "contact__urns__path__icontains" )
57
+ default_order = ("-created_on" , "-id" )
58
+ allow_export = False
59
+ bulk_actions = ()
60
+ bulk_action_permissions = {"resend" : "msgs.msg_create" , "delete" : "msgs.msg_update" }
55
61
system_label = None
56
62
paginate_by = 100
57
63
@@ -62,38 +68,6 @@ def pre_process(self, request, *args, **kwargs):
62
68
def derive_label (self ):
63
69
return self .system_label
64
70
65
- def get_context_data (self , ** kwargs ):
66
- org = self .request .org
67
- counts = SystemLabel .get_counts (org )
68
- label = self .derive_label ()
69
-
70
- # if there isn't a search filtering the queryset, we can replace the count function with a pre-calculated value
71
- if "search" not in self .request .GET :
72
- if isinstance (label , Label ):
73
- patch_queryset_count (self .object_list , label .get_visible_count )
74
- elif isinstance (label , str ):
75
- patch_queryset_count (self .object_list , lambda : counts [label ])
76
-
77
- context = super ().get_context_data (** kwargs )
78
- context ["has_messages" ] = (
79
- any (counts .values ()) or Archive .objects .filter (org = org , archive_type = Archive .TYPE_MSG ).exists ()
80
- )
81
-
82
- return context
83
-
84
-
85
- class MsgListView (ContextMenuMixin , BulkActionMixin , SystemLabelView ):
86
- """
87
- Base class for message list views with message folders and labels listed by the side
88
- """
89
-
90
- permission = "msgs.msg_list"
91
- search_fields = ("text__icontains" , "contact__name__icontains" , "contact__urns__path__icontains" )
92
- default_order = ("-created_on" , "-id" )
93
- allow_export = False
94
- bulk_actions = ()
95
- bulk_action_permissions = {"resend" : "msgs.msg_create" , "delete" : "msgs.msg_update" }
96
-
97
71
def derive_export_url (self ):
98
72
redirect = quote_plus (self .request .get_full_path ())
99
73
label = self .derive_label ()
@@ -114,6 +88,25 @@ def get_queryset(self, **kwargs):
114
88
115
89
return qs
116
90
91
+ def get_context_data (self , ** kwargs ):
92
+ org = self .request .org
93
+ counts = SystemLabel .get_counts (org )
94
+ label = self .derive_label ()
95
+
96
+ # if there isn't a search filtering the queryset, we can replace the count function with a pre-calculated value
97
+ if "search" not in self .request .GET :
98
+ if isinstance (label , Label ):
99
+ patch_queryset_count (self .object_list , label .get_visible_count )
100
+ elif isinstance (label , str ):
101
+ patch_queryset_count (self .object_list , lambda : counts [label ])
102
+
103
+ context = super ().get_context_data (** kwargs )
104
+ context ["has_messages" ] = (
105
+ any (counts .values ()) or Archive .objects .filter (org = org , archive_type = Archive .TYPE_MSG ).exists ()
106
+ )
107
+
108
+ return context
109
+
117
110
def get_bulk_action_labels (self ):
118
111
return self .request .org .msgs_labels .filter (is_active = True ).order_by (Lower ("name" ))
119
112
0 commit comments