Skip to content

Commit

Permalink
Merge pull request #5584 from nyaruka/campaign_list_cleanup
Browse files Browse the repository at this point in the history
Cleanup campaign list views
  • Loading branch information
rowanseymour authored Oct 25, 2024
2 parents edbace2 + 44a6167 commit f27867a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 68 deletions.
18 changes: 4 additions & 14 deletions temba/campaigns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def derive_menu(self):
icon="campaign_archived",
count=org.campaigns.filter(is_active=True, is_archived=True).count(),
href="campaigns.campaign_archived",
perm="campaigns.campaign_list",
)
)

Expand Down Expand Up @@ -162,27 +163,19 @@ def get_form_kwargs(self):
return kwargs

class BaseList(ContextMenuMixin, BulkActionMixin, BaseListView):
permission = "campaigns.campaign_list"
fields = ("name", "group")
default_template = "campaigns/campaign_list.html"
default_order = ("-modified_on",)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["org_has_campaigns"] = self.request.org.campaigns.exists()
context["request_url"] = self.request.path
return context

class List(BaseList):
title = _("Active")
fields = ("name", "group")
bulk_actions = ("archive",)
search_fields = ("name__icontains", "group__name__icontains")
menu_path = "/campaign/active"

def get_queryset(self, *args, **kwargs):
qs = super().get_queryset(*args, **kwargs)
qs = qs.filter(is_active=True, is_archived=False)
return qs
return super().get_queryset(*args, **kwargs).filter(is_archived=False)

def build_context_menu(self, menu):
if self.has_org_perm("campaigns.campaign_create"):
Expand All @@ -196,14 +189,11 @@ def build_context_menu(self, menu):

class Archived(BaseList):
title = _("Archived")
fields = ("name",)
bulk_actions = ("restore",)
menu_path = "/campaign/archived"

def get_queryset(self, *args, **kwargs):
qs = super().get_queryset(*args, **kwargs)
qs = qs.filter(is_active=True, is_archived=True)
return qs
return super().get_queryset(*args, **kwargs).filter(is_archived=True)

class Archive(OrgObjPermsMixin, SmartUpdateView):
fields = ()
Expand Down
3 changes: 1 addition & 2 deletions temba/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
),
"api.apitoken": ("explorer",),
"archives.archive": ("run", "message"),
"campaigns.campaign": ("archived", "archive", "activate", "menu"),
"campaigns.campaign": ("archive", "activate", "menu"),
"channels.channel": ("chart", "claim", "configuration", "errors", "facebook_whitelist"),
"channels.channellog": ("connection",),
"classifiers.classifier": ("connect", "sync"),
Expand Down Expand Up @@ -595,7 +595,6 @@
"triggers.trigger.*",
),
"Viewers": (
"campaigns.campaign_archived",
"campaigns.campaign_list",
"campaigns.campaign_menu",
"campaigns.campaign_read",
Expand Down
86 changes: 34 additions & 52 deletions templates/campaigns/campaign_list.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
{% extends "smartmin/list.html" %}
{% load smartmin sms temba compress i18n humanize %}
{% extends "orgs/base/list.html" %}
{% load i18n humanize %}

{% block extra-style %}
{{ block.super }}
<style type="text/css">
temba-button {
display: block;
}
</style>
{% endblock extra-style %}
{% block table %}
<table class="list lined selectable scrolled">
<tbody>
{% for obj in object_list %}
<tr data-object-id="{{ obj.id }}"
data-uuid="{{ obj.uuid }}"
onclick="handleRowClicked(event)"
href="{% url 'campaigns.campaign_read' obj.uuid %}"
class="campaign object-row select-row">
{% if org_perms.campaigns.campaign_update %}
<td onclick="checkInner(event);" class="campaign checkbox object-row-checkbox">
<temba-checkbox onclick="handleRowSelection(this)">
</temba-checkbox>
</td>
{% endif %}
<td class="w-full">{{ obj.name }}</td>
<td class="whitespace-nowrap">
{# in the past we let users delete groups used by campaigns #}
{% if obj.group.is_active %}
<div class="recipients inline-block">{% include "includes/recipients_group.html" with group=obj.group %}</div>
{% endif %}
</td>
<td class="whitespace-nowrap">{{ obj.get_events|length }} event{{ obj.get_events|length|pluralize }}</td>
</tr>
{% empty %}
<tr class="empty_list">
<td colspan="99" class="text-center">{% trans "No campaigns" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock table %}
{% block extra-script %}
{{ block.super }}
<script type="text/javascript">
Expand All @@ -22,45 +46,3 @@
}
</script>
{% endblock extra-script %}
{% block content %}
<form method="get" action="{{ request.path }}" id="search-form">
<temba-textinput placeholder="{% trans "Search" %}" name="search" value="{{ search }}" class="w-full">
</temba-textinput>
<input type="submit" class="hide">
</form>
<div class="mt-4 shadow rounded-lg rounded-bl-none rounded-br-none bg-white">{% include "includes/short_pagination.html" %}</div>
<div class="flex-grow overflow-y-auto shadow">
<table class="list lined selectable scrolled">
<tbody>
{% for obj in object_list %}
<tr data-object-id="{{ obj.id }}"
data-uuid="{{ obj.uuid }}"
onclick="handleRowClicked(event)"
href="{% url 'campaigns.campaign_read' obj.uuid %}"
class="campaign object-row select-row">
{% if org_perms.campaigns.campaign_update %}
<td onclick="checkInner(event);" class="campaign checkbox object-row-checkbox">
<temba-checkbox onclick="handleRowSelection(this)">
</temba-checkbox>
</td>
{% endif %}
<td class="w-full">{{ obj.name }}</td>
<td class="whitespace-nowrap">
{# in the past we let users delete groups used by campaigns #}
{% if obj.group.is_active %}
<div class="recipients inline-block">{% include "includes/recipients_group.html" with group=obj.group %}</div>
{% endif %}
</td>
<td class="whitespace-nowrap">{{ obj.get_events|length }} event{{ obj.get_events|length|pluralize }}</td>
</tr>
{% empty %}
<tr class="empty_list">
<td colspan="99" class="text-center">{% trans "No campaigns" %}</td>
</tr>
{% endfor %}
{% block extra-rows %}
{% endblock extra-rows %}
</tbody>
</table>
</div>
{% endblock content %}

0 comments on commit f27867a

Please sign in to comment.