2022-07-21 12:46:34 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.shortcuts import render
|
2022-07-21 12:46:48 +00:00
|
|
|
from django.views import View
|
|
|
|
|
|
|
|
from core.lib.opensearch import initialise_opensearch, run_main_query
|
|
|
|
|
|
|
|
client = initialise_opensearch()
|
2022-07-21 12:46:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Drilldown(LoginRequiredMixin, View):
|
|
|
|
template_name = "ui/drilldown.html"
|
|
|
|
|
2022-07-21 12:46:48 +00:00
|
|
|
def get(self, request):
|
|
|
|
if not request.user.has_plan("drilldown"):
|
|
|
|
return render(request, "denied.html")
|
|
|
|
return render(request, self.template_name)
|
|
|
|
|
|
|
|
def post(self, request):
|
2022-07-21 12:46:34 +00:00
|
|
|
if not request.user.has_plan("drilldown"):
|
|
|
|
return render(request, "denied.html")
|
2022-07-21 12:46:48 +00:00
|
|
|
if "query" in request.POST:
|
|
|
|
query = request.POST["query"]
|
|
|
|
results = run_main_query(client, query)
|
|
|
|
print("RESULTS", results)
|
|
|
|
context = {"query": query}
|
|
|
|
print("CONTEXT", context)
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
return render(request, self.template_name)
|