Skip to content

Commit

Permalink
Use flow id for category and result views
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 28, 2024
1 parent 592d755 commit 901b7b5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions temba/flows/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ def test_views(self):
self.assertRedirect(response, reverse("flows.flow_editor", args=[flow3.uuid]))

# can see results for a flow
response = self.client.get(reverse("flows.flow_results", args=[flow.uuid]))
response = self.client.get(reverse("flows.flow_results", args=[flow.id]))
self.assertEqual(200, response.status_code)

# check flow listing
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def add_recent_contact(exit_uuid: str, dest_uuid: str, contact, text: str, ts: f
def test_category_counts(self):
flow1 = self.create_flow("Test 1")

counts_url = reverse("flows.flow_category_counts", args=[flow1.uuid])
counts_url = reverse("flows.flow_category_counts", args=[flow1.id])

self.assertRequestDisallowed(counts_url, [None, self.agent])

Expand Down Expand Up @@ -2384,7 +2384,7 @@ def test_category_counts(self):
def test_results(self):
flow = self.create_flow("Test 1")

results_url = reverse("flows.flow_results", args=[flow.uuid])
results_url = reverse("flows.flow_results", args=[flow.id])

self.assertRequestDisallowed(results_url, [None, self.agent])
self.assertReadFetch(results_url, [self.user, self.editor, self.admin])
Expand Down
18 changes: 7 additions & 11 deletions temba/flows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def build_context_menu(self, menu):
)

if self.has_org_perm("flows.flow_results"):
menu.add_link(_("Results"), reverse("flows.flow_results", args=[obj.uuid]))
menu.add_link(_("Results"), reverse("flows.flow_results", args=[obj.id]))

menu.new_group()

Expand Down Expand Up @@ -1224,27 +1224,23 @@ class CategoryCounts(BaseReadView):
"""

permission = "flows.flow_results"
slug_url_kwarg = "uuid"

def render_to_response(self, context, **response_kwargs):
return JsonResponse({"counts": self.object.get_category_counts()})

class Results(SpaMixin, ContextMenuMixin, BaseReadView):
slug_url_kwarg = "uuid"

def build_context_menu(self, menu):
obj = self.get_object()

if self.has_org_perm("flows.flow_editor"):
menu.add_link(_("Editor"), reverse("flows.flow_editor", args=[obj.uuid]), as_button=True)

if self.has_org_perm("flows.flow_results"):
menu.add_modax(
_("Export"),
"export-results",
f"{reverse('flows.flow_export_results')}?ids={obj.id}",
title=_("Export Results"),
)
menu.add_modax(
_("Export"),
"export-results",
f"{reverse('flows.flow_export_results')}?ids={obj.id}",
title=_("Export Results"),
)

def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions templates/flows/flow_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
{% endif %}
{% if object.run_stats.total %}
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
href="{% url "flows.flow_results" object.id %}"
class="linked mr-2 whitespace-nowrap">{{ object.run_stats.total|intcomma }}</div>
/
<div onclick="goto(event)"
href="{% url "flows.flow_results" object.uuid %}"
href="{% url "flows.flow_results" object.id %}"
class="text-center linked mx-2 whitespace-nowrap">{{ object.run_stats.completion }}%</div>
{% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/flows/flow_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
return;
}

store.getUrl("/flow/category_counts/{{object.uuid}}/", {
store.getUrl("/flow/category_counts/{{object.id}}/", {
force: true
}).then(function(response) {
var data = response.json;
Expand Down

0 comments on commit 901b7b5

Please sign in to comment.