Skip to content

Commit

Permalink
Remove pre-spa days code from flow list view
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 17, 2024
1 parent 80aeb60 commit c3ddb6b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 201 deletions.
14 changes: 0 additions & 14 deletions temba/flows/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,8 +2007,6 @@ def test_list_views(self):
response = self.client.get(reverse("flows.flow_list"))
self.assertContains(response, flow1.name)
self.assertContains(response, flow3.name)
self.assertEqual(2, response.context["folders"][0]["count"])
self.assertEqual(1, response.context["folders"][1]["count"])

# archive it
response = self.client.post(reverse("flows.flow_list"), {"action": "archive", "objects": flow1.id})
Expand All @@ -2018,8 +2016,6 @@ def test_list_views(self):
response = self.client.get(reverse("flows.flow_list"))
self.assertNotContains(response, flow1.name)
self.assertContains(response, flow3.name)
self.assertEqual(1, response.context["folders"][0]["count"])
self.assertEqual(2, response.context["folders"][1]["count"])

self.assertEqual(("archive", "label", "export-results"), response.context["actions"])

Expand All @@ -2044,8 +2040,6 @@ def test_list_views(self):
response = self.client.get(reverse("flows.flow_list"))
self.assertContains(response, flow1.name)
self.assertContains(response, flow3.name)
self.assertEqual(2, response.context["folders"][0]["count"])
self.assertEqual(1, response.context["folders"][1]["count"])

# can label flows
label1 = FlowLabel.create(self.org, self.admin, "Important")
Expand Down Expand Up @@ -2073,25 +2067,18 @@ def test_list_views(self):

response = self.client.get(reverse("flows.flow_list"))
self.assertContains(response, flow1.name)
self.assertEqual(2, response.context["folders"][0]["count"])
self.assertEqual(1, response.context["folders"][1]["count"])

# single message flow (flom campaign) should not be included in counts and not even on this list
Flow.objects.filter(id=flow1.id).update(is_system=True)

response = self.client.get(reverse("flows.flow_list"))

self.assertNotContains(response, flow1.name)
self.assertEqual(1, response.context["folders"][0]["count"])
self.assertEqual(1, response.context["folders"][1]["count"])

# single message flow should not be even in the archived list
Flow.objects.filter(id=flow1.id).update(is_system=True, is_archived=True)

response = self.client.get(reverse("flows.flow_archived"))
self.assertNotContains(response, flow1.name)
self.assertEqual(1, response.context["folders"][0]["count"])
self.assertEqual(1, response.context["folders"][1]["count"]) # only flow2

def test_filter(self):
flow1 = self.create_flow("Flow 1")
Expand All @@ -2107,7 +2094,6 @@ def test_filter(self):

response = self.client.get(reverse("flows.flow_filter", args=[label1.uuid]))
self.assertEqual([flow2, flow1], list(response.context["object_list"]))
self.assertEqual(2, len(response.context["labels"]))
self.assertEqual(("label", "export-results"), response.context["actions"])

response = self.client.get(reverse("flows.flow_filter", args=[label2.uuid]))
Expand Down
58 changes: 2 additions & 56 deletions temba/flows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.conf import settings
from django.contrib.humanize.templatetags import humanize
from django.core.exceptions import ValidationError
from django.db.models import Count, Max, Min, Sum
from django.db.models import Max, Min, Sum
from django.db.models.functions import Lower
from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse
from django.urls import reverse
Expand Down Expand Up @@ -669,19 +669,14 @@ def update_triggers(self, flow, user, new_keywords: list):
class BaseList(BulkActionMixin, ContextMenuMixin, BaseListView):
permission = "flows.flow_list"
title = _("Flows")
refresh = 10000
fields = ("name", "modified_on")
default_template = "flows/flow_list.html"
default_order = ("-saved_on",)
search_fields = ("name__icontains",)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["org_has_flows"] = self.request.org.flows.filter(is_active=True).exists()
context["folders"] = self.get_folders()
context["labels"] = self.get_flow_labels()
context["campaigns"] = self.get_campaigns()
context["request_url"] = self.request.path
context["labels"] = self.request.org.flow_labels.order_by(Lower("name"))

# decorate flow objects with their run activity stats
for flow in context["object_list"]:
Expand All @@ -693,22 +688,6 @@ def derive_queryset(self, *args, **kwargs):
qs = super().derive_queryset(*args, **kwargs)
return qs.exclude(is_system=True).exclude(is_active=False)

def get_campaigns(self):
from temba.campaigns.models import CampaignEvent

org = self.request.org
events = CampaignEvent.objects.filter(
campaign__org=org,
is_active=True,
campaign__is_active=True,
flow__is_archived=False,
flow__is_active=True,
flow__is_system=False,
)
return (
events.values("campaign__name", "campaign__id").annotate(count=Count("id")).order_by("campaign__name")
)

def apply_bulk_action(self, user, action, objects, label):
super().apply_bulk_action(user, action, objects, label)

Expand All @@ -724,39 +703,6 @@ def apply_bulk_action(self, user, action, objects, label):
def get_bulk_action_labels(self):
return self.request.org.flow_labels.filter(is_active=True)

def get_flow_labels(self):
labels = []
for label in self.request.org.flow_labels.order_by("name"):
labels.append(
{
"id": label.id,
"uuid": label.uuid,
"name": label.name,
"count": label.get_flow_count(),
}
)
return labels

def get_folders(self):
org = self.request.org

return [
dict(
label="Active",
url=reverse("flows.flow_list"),
count=Flow.objects.exclude(is_system=True)
.filter(is_active=True, is_archived=False, org=org)
.count(),
),
dict(
label="Archived",
url=reverse("flows.flow_archived"),
count=Flow.objects.exclude(is_system=True)
.filter(is_active=True, is_archived=True, org=org)
.count(),
),
]

def build_context_menu(self, menu):
if self.has_org_perm("flows.flow_create"):
menu.add_modax(
Expand Down
18 changes: 0 additions & 18 deletions templates/flows/empty_include.html

This file was deleted.

19 changes: 0 additions & 19 deletions templates/flows/flow_filter.html

This file was deleted.

184 changes: 90 additions & 94 deletions templates/flows/flow_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "smartmin/list.html" %}
{% load smartmin sms temba compress i18n humanize %}
{% load smartmin temba i18n humanize %}

{% block content %}
{% if org_perms.flows.flow_results %}
Expand All @@ -14,102 +14,98 @@
id="create-label-modal">
</temba-modax>
{% endif %}
{% if org_has_flows %}
<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="relative list object-list lined selectable scrolled">
{% if object_list %}
<thead>
<tr>
{% if org_perms.flows.flow_update %}<th></th>{% endif %}
<th></th>
<th style="text-align:right" class="whitespace-nowrap">Runs / Completion</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for object in object_list %}
<tr onclick="handleRowClicked(event)"
data-uuid="{{ object.uuid }}"
data-object-id="{{ object.id }}"
href="{% url 'flows.flow_editor' object.uuid %}"
class="object-row select-row">
{% if org_perms.flows.flow_update %}
<td onclick="checkInner(event);" style="width:0px" class="checkbox object-row-checkbox">
<temba-checkbox onclick="handleRowSelection(this)">
</temba-checkbox>
</td>
{% endif %}
<td>
<div class="flex items-center">
<div class="flex-grow">
<div style="max-width:80%" class="flex whitespace-nowrap flex-grow items-center">
<div class="flex items-center text-gray-600">
{% if object.flow_type == 'V' %}
<temba-icon name="flow_ivr" class="mr-2">
</temba-icon>
{% elif object.flow_type == 'S' %}
<temba-icon name="flow_surveyor" class="mr-2">
</temba-icon>
{% elif object.flow_type == 'B' %}
<temba-icon name="flow_background" class="mr-2">
</temba-icon>
{% endif %}
</div>
<div class="name truncate flex-grow">{{ object.name }}</div>
<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="relative list object-list lined selectable scrolled">
{% if object_list %}
<thead>
<tr>
{% if org_perms.flows.flow_update %}<th></th>{% endif %}
<th></th>
<th style="text-align:right" class="whitespace-nowrap">Runs / Completion</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for object in object_list %}
<tr onclick="handleRowClicked(event)"
data-uuid="{{ object.uuid }}"
data-object-id="{{ object.id }}"
href="{% url 'flows.flow_editor' object.uuid %}"
class="object-row select-row">
{% if org_perms.flows.flow_update %}
<td onclick="checkInner(event);" style="width:0px" class="checkbox object-row-checkbox">
<temba-checkbox onclick="handleRowSelection(this)">
</temba-checkbox>
</td>
{% endif %}
<td>
<div class="flex items-center">
<div class="flex-grow">
<div style="max-width:80%" class="flex whitespace-nowrap flex-grow items-center">
<div class="flex items-center text-gray-600">
{% if object.flow_type == 'V' %}
<temba-icon name="flow_ivr" class="mr-2">
</temba-icon>
{% elif object.flow_type == 'S' %}
<temba-icon name="flow_surveyor" class="mr-2">
</temba-icon>
{% elif object.flow_type == 'B' %}
<temba-icon name="flow_background" class="mr-2">
</temba-icon>
{% endif %}
</div>
</div>
<div class="whitespace-no-break flex items-center ml-2 justify-end flex-wrap">
{% for label in object.labels.all %}
<a href="{% url 'flows.flow_filter' label.uuid %}" onclick="goto(event, this)">
<temba-label data-id="{{ label.id }}" icon="label" clickable class="mx-1 my-1">
{{ label.name }}
</temba-label>
</a>
{% endfor %}
<div class="name truncate flex-grow">{{ object.name }}</div>
</div>
</div>
</td>
<td>
{% if not object.is_archived %}
<div class="whitespace-no-break flex items-center justify-end">
{% if object.has_issues %}
<div>
<temba-tip position="top" text="{{ _("Has issues") |escapejs }}" slot="toggle">
<temba-icon name="issue" class="mr-2" clickable="true">
</temba-icon>
</temba-tip>
</div>
{% endif %}
{% if object.run_stats.total %}
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
class="linked mr-2 whitespace-nowrap">{{ object.run_stats.total|intcomma }}</div>
/
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
class="text-center linked mx-2 whitespace-nowrap">{{ object.run_stats.completion }}%</div>
{% endif %}
</div>
{% endif %}
</td>
</tr>
{% empty %}
<tr class="empty_list">
<td colspan="99" class="text-center">{% trans "No flows" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
{% include "flows/empty_include.html" %}
{% endif %}
<div class="whitespace-no-break flex items-center ml-2 justify-end flex-wrap">
{% for label in object.labels.all %}
<a href="{% url 'flows.flow_filter' label.uuid %}" onclick="goto(event, this)">
<temba-label data-id="{{ label.id }}" icon="label" clickable class="mx-1 my-1">
{{ label.name }}
</temba-label>
</a>
{% endfor %}
</div>
</div>
</td>
<td>
{% if not object.is_archived %}
<div class="whitespace-no-break flex items-center justify-end">
{% if object.has_issues %}
<div>
<temba-tip position="top" text="{{ _("Has issues") |escapejs }}" slot="toggle">
<temba-icon name="issue" class="mr-2" clickable="true">
</temba-icon>
</temba-tip>
</div>
{% endif %}
{% if object.run_stats.total %}
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
class="linked mr-2 whitespace-nowrap">{{ object.run_stats.total|intcomma }}</div>
/
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
class="text-center linked mx-2 whitespace-nowrap">{{ object.run_stats.completion }}%</div>
{% endif %}
</div>
{% endif %}
</td>
</tr>
{% empty %}
<tr class="empty_list">
<td colspan="99" class="text-center">{% trans "No flows" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock content %}
{% block extra-script %}
{{ block.super }}
Expand Down

0 comments on commit c3ddb6b

Please sign in to comment.