Combine homepage and search into one class

Mark Veidemanis 2 years ago
parent 56f2c96b45
commit c1071f3d55
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -51,11 +51,7 @@ from core.views.manage.threshold.threshold import (
) )
# Main tool pages # Main tool pages
from core.views.ui.drilldown import ( # DrilldownTableView, from core.views.ui.drilldown import Drilldown, ThresholdInfoModal # DrilldownTableView,
Drilldown,
DrilldownSearch,
ThresholdInfoModal,
)
from core.views.ui.insights import ( from core.views.ui.insights import (
Insights, Insights,
InsightsChannels, InsightsChannels,
@ -85,9 +81,8 @@ urlpatterns = [
path("accounts/", include("django.contrib.auth.urls")), path("accounts/", include("django.contrib.auth.urls")),
path("accounts/signup/", Signup.as_view(), name="signup"), path("accounts/signup/", Signup.as_view(), name="signup"),
## ##
path("ui/drilldown/", Drilldown.as_view(), name="drilldown"), # path("drilldown/", Drilldown.as_view(), name="drilldown"),
path("ui/drilldown/modal/", ThresholdInfoModal.as_view(), name="modal_drilldown"), path("modal/", ThresholdInfoModal.as_view(), name="modal_drilldown"),
path("ui/drilldown/search/", DrilldownSearch.as_view(), name="search_drilldown"),
## ##
path("ui/insights/", Insights.as_view(), name="insights"), path("ui/insights/", Insights.as_view(), name="insights"),
path("ui/insights/search/", InsightsSearch.as_view(), name="search_insights"), path("ui/insights/search/", InsightsSearch.as_view(), name="search_insights"),

@ -66,7 +66,7 @@
} }
</script> </script>
<div> <div>
<form method="POST" hx-post="{% url 'search_drilldown' %}" <form method="POST" hx-post="{% url 'home' %}"
hx-trigger="change" hx-trigger="change"
hx-target="#results" hx-target="#results"
hx-swap="innerHTML" hx-swap="innerHTML"
@ -78,7 +78,7 @@
<div class="field has-addons"> <div class="field has-addons">
<div class="control is-expanded has-icons-left"> <div class="control is-expanded has-icons-left">
<input <input
hx-post="{% url 'search_drilldown' %}" hx-post="{% url 'home' %}"
hx-trigger="keyup changed delay:200ms" hx-trigger="keyup changed delay:200ms"
hx-target="#results" hx-target="#results"
hx-swap="innerHTML" id="query" name="query" class="input" type="text" placeholder="msg: science AND nick: BillNye AND channel: #science"> hx-swap="innerHTML" id="query" name="query" class="input" type="text" placeholder="msg: science AND nick: BillNye AND channel: #science">
@ -91,7 +91,7 @@
<button <button
id="search" id="search"
class="button is-info is-fullwidth" class="button is-info is-fullwidth"
hx-post="{% url 'search_drilldown' %}" hx-post="{% url 'home' %}"
hx-trigger="click" hx-trigger="click"
hx-target="#results" hx-target="#results"
hx-swap="innerHTML"> hx-swap="innerHTML">

@ -1,8 +1,10 @@
import json import json
import urllib
from django.conf import settings from django.conf import settings
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from django.shortcuts import render from django.shortcuts import render
from django.urls import reverse
from django.views import View from django.views import View
from django_tables2 import SingleTableMixin from django_tables2 import SingleTableMixin
from rest_framework.parsers import FormParser from rest_framework.parsers import FormParser
@ -49,8 +51,6 @@ class Drilldown(View):
plan_name = "drilldown" plan_name = "drilldown"
def get(self, request): def get(self, request):
# if not request.user.has_plan(self.plan_name):
# return render(request, "denied.html")
if request.user.is_anonymous: if request.user.is_anonymous:
sizes = settings.OPENSEARCH_MAIN_SIZES_ANON sizes = settings.OPENSEARCH_MAIN_SIZES_ANON
else: else:
@ -60,16 +60,15 @@ class Drilldown(View):
} }
return render(request, self.template_name, context) return render(request, self.template_name, context)
class DrilldownSearch(View):
# parser_classes = [JSONParser]
template_name = "ui/drilldown/results.html"
plan_name = "drilldown"
def post(self, request): def post(self, request):
# if not request.user.has_plan(self.plan_name): template_name = "ui/drilldown/results.html"
# return HttpResponseForbidden() data_args = request.POST.dict()
del data_args["csrfmiddlewaretoken"]
print("rep", repr(data_args["dates"]))
if data_args["dates"] == " - ":
del data_args["dates"]
url_params = urllib.parse.urlencode(data_args)
print("url_params", url_params)
context = query_results(request) context = query_results(request)
if "message" in context: if "message" in context:
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -86,7 +85,9 @@ class DrilldownSearch(View):
] ]
) )
if context: if context:
return render(request, self.template_name, context) response = render(request, template_name, context)
response["HX-Push"] = reverse("home") + "?" + url_params
return response
else: else:
return HttpResponse("No results") return HttpResponse("No results")

Loading…
Cancel
Save