This commit is contained in:
Mark Veidemanis 2022-08-11 23:09:53 +01:00
parent 5fd6b887de
commit 7791e96809
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 14 additions and 7 deletions

View File

@ -187,7 +187,6 @@ def query_results(request, query_params, size=None):
return {"message": message, "class": message_class} return {"message": message, "class": message_class}
if source != "all": if source != "all":
add_bool.append({"src": source}) add_bool.append({"src": source})
if set({"from_date", "to_date", "from_time", "to_time"}).issubset( if set({"from_date", "to_date", "from_time", "to_time"}).issubset(
query_params.keys() query_params.keys()
): ):
@ -267,6 +266,7 @@ def query_results(request, query_params, size=None):
search_query["query"]["bool"]["must_not"] = [item] search_query["query"]["bool"]["must_not"] = [item]
if sort: if sort:
search_query["sort"] = sort search_query["sort"] = sort
if "index" in query_params: if "index" in query_params:
if not request.user.is_superuser: if not request.user.is_superuser:
message = "How did you get here?" message = "How did you get here?"
@ -340,12 +340,17 @@ def query_results(request, query_params, size=None):
def query_single_result(request): def query_single_result(request):
context = query_results(request, 1) context = query_results(request, request.POST.dict(), size=100)
dedup_set = {item["nick"] for item in context["results"]}
if dedup_set:
context["item"] = context["results"][0]
return (1, context) if not context:
return {"message": "Failed to run query", "message_class": "danger"}
if "message" in context:
return context
dedup_set = {item["nick"] for item in context["object_list"]}
if dedup_set:
context["item"] = context["object_list"][0]
return context
def construct_query(query, size): def construct_query(query, size):

View File

@ -19,6 +19,7 @@
hx-swap="outerHTML"> hx-swap="outerHTML">
</div> </div>
<div id="info"> <div id="info">
{% include 'partials/notify.html' %}
{% if item is not None %} {% if item is not None %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">

View File

@ -1,6 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static %}
{% block content %} {% block content %}
{% include 'partials/notify.html' %}
<script> <script>
// tabbed browsing for the modal // tabbed browsing for the modal
function initTabs() { function initTabs() {

View File

@ -37,7 +37,7 @@ class InsightsSearch(LoginRequiredMixin, View):
def post(self, request): def post(self, request):
if not request.user.has_plan(self.plan_name): if not request.user.has_plan(self.plan_name):
return HttpResponseForbidden() return HttpResponseForbidden()
results, context = query_single_result(request) context = query_single_result(request)
if not context: if not context:
return HttpResponseForbidden() return HttpResponseForbidden()
return render(request, self.template_name, context) return render(request, self.template_name, context)