neptune/core/ui/views/drilldown.py

33 lines
1.2 KiB
Python

from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views import View
from core.lib.opensearch import initialise_opensearch, run_main_query
client = initialise_opensearch()
class Drilldown(LoginRequiredMixin, View):
template_name = "ui/drilldown.html"
plan_name = "drilldown"
def get(self, request):
if not request.user.has_plan(self.plan_name):
return render(request, "denied.html")
return render(request, self.template_name)
def post(self, request):
if not request.user.has_plan(self.plan_name):
return render(request, "denied.html")
if "query" in request.POST:
query = request.POST["query"]
results = run_main_query(client, query)
results_parsed = []
if "hits" in results.keys():
if "hits" in results["hits"]:
for item in results["hits"]["hits"]:
results_parsed.append(item["_source"])
context = {"query": query, "results": results_parsed}
return render(request, self.template_name, context)
return render(request, self.template_name)