Skip to content

Commit e0c09a7

Browse files
committed
Merge SystemLabelView into MsgListView
1 parent eb62a86 commit e0c09a7

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

temba/ivr/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from smartmin.views import SmartCRUDL
22

33
from django.utils.translation import gettext_lazy as _
4+
45
from temba.orgs.views.base import BaseListView
56
from temba.utils.views.mixins import SpaMixin
67

temba/msgs/views.py

+27-34
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@
4747
from .models import Broadcast, Label, LabelCount, Media, MessageExport, Msg, OptIn, SystemLabel
4848

4949

50-
class SystemLabelView(SpaMixin, BaseListView):
50+
class MsgListView(ContextMenuMixin, BulkActionMixin, SpaMixin, BaseListView):
5151
"""
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
5353
"""
5454

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"}
5561
system_label = None
5662
paginate_by = 100
5763

@@ -62,38 +68,6 @@ def pre_process(self, request, *args, **kwargs):
6268
def derive_label(self):
6369
return self.system_label
6470

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-
9771
def derive_export_url(self):
9872
redirect = quote_plus(self.request.get_full_path())
9973
label = self.derive_label()
@@ -114,6 +88,25 @@ def get_queryset(self, **kwargs):
11488

11589
return qs
11690

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+
117110
def get_bulk_action_labels(self):
118111
return self.request.org.msgs_labels.filter(is_active=True).order_by(Lower("name"))
119112

0 commit comments

Comments
 (0)