From 220a4e245199f3a56fc16c6431591dd6bd68ee12 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 9 Aug 2022 11:54:44 +0100 Subject: [PATCH] Properly format templates --- app/urls.py | 3 +- core/lib/opensearch.py | 12 +- core/templates/ui/drilldown/drilldown.html | 3 +- core/templates/ui/drilldown/results.html | 66 ++++++----- .../templates/ui/drilldown/table_results.html | 22 ++-- .../ui/drilldown/table_results_partial.html | 106 +++++++++--------- core/templatetags/hy.py | 8 ++ core/views/ui/drilldown.py | 3 +- core/views/ui/tables.py | 3 +- 9 files changed, 122 insertions(+), 104 deletions(-) create mode 100644 core/templatetags/hy.py diff --git a/app/urls.py b/app/urls.py index a7e0e26..84d43ad 100644 --- a/app/urls.py +++ b/app/urls.py @@ -51,10 +51,9 @@ from core.views.manage.threshold.threshold import ( ) # Main tool pages -from core.views.ui.drilldown import ( +from core.views.ui.drilldown import ( # DrilldownTableView, Drilldown, DrilldownSearch, - DrilldownTableView, ThresholdInfoModal, ) from core.views.ui.insights import ( diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index c829701..926ebbe 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -136,7 +136,7 @@ def run_main_query(client, user, query, custom_query=False, index=None, size=Non response = client.search(body=search_query, index=index) except RequestError as err: print("OpenSearch error", err) - return False + return err filter_blacklisted(user, response) return response @@ -268,6 +268,15 @@ def query_results(request, size=None): ) if not results: return False + if isinstance(results, RequestError): + message = results.info["error"]["root_cause"][0]["reason"] + message_class = "danger" + return {"message": message, "class": message_class} + if len(results["hits"]["hits"]) == 0: + message = "No results." + message_class = "danger" + return {"message": message, "class": message_class} + results_parsed = [] if "hits" in results.keys(): if "hits" in results["hits"]: @@ -289,7 +298,6 @@ def query_results(request, size=None): element["date"] = date element["time"] = time results_parsed.append(element) - annotate_results(results_parsed) context = { diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index 81cb937..de3a889 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static %} +{% load hy %} {% block content %}