From a7ee1d531f335d616276fb259dd72b3fc9191ba4 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 9 Aug 2022 07:20:30 +0100 Subject: [PATCH] Push the URL earlier and don't check for field present --- core/views/ui/drilldown.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index 723cc64..2fbd5da 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -112,6 +112,12 @@ def drilldown_search(request, return_context=False, template=None): elif request.POST: context = query_results(request, query_params) + # URI we're passing to the template for linking + if "csrfmiddlewaretoken" in query_params: + del query_params["csrfmiddlewaretoken"] + url_params = urllib.parse.urlencode(query_params) + context["client_uri"] = url_params + # Turn the query into tags for populating the taglist if "query" in query_params: tags = create_tags(query_params["query"]) @@ -119,7 +125,13 @@ def drilldown_search(request, return_context=False, template=None): context["params"] = query_params if "message" in context: - return render(request, template_name, context) + response = render(request, template_name, context) + if request.GET: + if request.htmx: + response["HX-Push"] = reverse("home") + "?" + url_params + elif request.POST: + response["HX-Push"] = reverse("home") + "?" + url_params + return response # Create data for chart.js sentiment graph graph = make_graph(context["object_list"]) @@ -129,12 +141,6 @@ def drilldown_search(request, return_context=False, template=None): context["sizes"] = sizes context = make_table(context) - # URI we're passing to the template for linking - if "csrfmiddlewaretoken" in query_params: - del query_params["csrfmiddlewaretoken"] - url_params = urllib.parse.urlencode(query_params) - context["client_uri"] = url_params - # URI we're passing to the template for linking, table fields removed table_fields = ["page", "sort"] clean_params = {k: v for k, v in query_params.items() if k not in table_fields} @@ -176,10 +182,10 @@ class DrilldownTableView(SingleTableView): first = self.object_list[0] fields = first.keys() for field in fields: - values_present = all([x[field] is not None for x in self.object_list]) - if values_present: - if field not in show: - show.append(field) + # values_present = all([x[field] is not None for x in self.object_list]) + # if values_present: + if field not in show: + show.append(field) allow_empty = self.get_allow_empty() if not allow_empty: