diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index a64cc38..fc2ac89 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -96,122 +96,6 @@ def make_graph(results): return orjson.dumps(graph).decode("utf-8") -def drilldown_search(request, return_context=False, template=None): - extra_params = {} - - if not template: - template_name = "widgets/table_results.html" - else: - template_name = template - if request.user.is_anonymous: - sizes = settings.MAIN_SIZES_ANON - else: - sizes = settings.MAIN_SIZES - - if request.GET: - if not request.htmx: - template_name = "ui/drilldown/drilldown.html" - query_params = request.GET.dict() - elif request.POST: - query_params = request.POST.dict() - else: - template_name = "ui/drilldown/drilldown.html" - params_with_defaults = {} - helpers.add_defaults(params_with_defaults) - context = {"sizes": sizes, "unique": "results", "params": params_with_defaults} - return render(request, template_name, context) - - tmp_post = request.POST.dict() - tmp_get = request.GET.dict() - tmp_post = {k: v for k, v in tmp_post.items() if v and not v == "None"} - tmp_get = {k: v for k, v in tmp_get.items() if v and not v == "None"} - query_params.update(tmp_post) - query_params.update(tmp_get) - - # URI we're passing to the template for linking - if "csrfmiddlewaretoken" in query_params: - del query_params["csrfmiddlewaretoken"] - - # Parse the dates - if "dates" in query_params: - dates = parse_dates(query_params["dates"]) - del query_params["dates"] - if dates: - if "message" in dates: - return render(request, template_name, dates) - query_params["from_date"] = dates["from_date"] - query_params["to_date"] = dates["to_date"] - query_params["from_time"] = dates["from_time"] - query_params["to_time"] = dates["to_time"] - - if "query" in query_params: - # Remove null values - if query_params["query"] == "": - del query_params["query"] - # Turn the query into tags for populating the taglist - # tags = create_tags(query_params["query"]) - # context["tags"] = tags - # else: - # context = {"object_list": []} - - if "tags" in query_params: - if query_params["tags"] == "": - del query_params["tags"] - else: - tags = parse_tags(query_params["tags"]) - extra_params["tags"] = tags - - context = db.query_results(request, query_params, **extra_params) - context["unique"] = "results" - - # Valid sizes - context["sizes"] = sizes - - # Add any default parameters to the context - params_with_defaults = dict(query_params) - helpers.add_defaults(params_with_defaults) - context["params"] = params_with_defaults - - helpers.remove_defaults(query_params) - url_params = urllib.parse.urlencode(query_params) - context["client_uri"] = url_params - if "message" in context: - if return_context: - return 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"]) - context["data"] = graph - - context = make_table(context) - - # 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} - clean_url_params = urllib.parse.urlencode(clean_params) - context["uri"] = clean_url_params - - # unique = str(uuid.uuid4())[:8] - if return_context: - return 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 - - class DrilldownTableView(SingleTableView): table_class = DrilldownTable template_name = "wm/widget.html"