Combine homepage and search into one class
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
}
|
||||
</script>
|
||||
<div>
|
||||
<form method="POST" hx-post="{% url 'search_drilldown' %}"
|
||||
<form method="POST" hx-post="{% url 'home' %}"
|
||||
hx-trigger="change"
|
||||
hx-target="#results"
|
||||
hx-swap="innerHTML"
|
||||
@@ -78,7 +78,7 @@
|
||||
<div class="field has-addons">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<input
|
||||
hx-post="{% url 'search_drilldown' %}"
|
||||
hx-post="{% url 'home' %}"
|
||||
hx-trigger="keyup changed delay:200ms"
|
||||
hx-target="#results"
|
||||
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
|
||||
id="search"
|
||||
class="button is-info is-fullwidth"
|
||||
hx-post="{% url 'search_drilldown' %}"
|
||||
hx-post="{% url 'home' %}"
|
||||
hx-trigger="click"
|
||||
hx-target="#results"
|
||||
hx-swap="innerHTML">
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
from django_tables2 import SingleTableMixin
|
||||
from rest_framework.parsers import FormParser
|
||||
@@ -49,8 +51,6 @@ class Drilldown(View):
|
||||
plan_name = "drilldown"
|
||||
|
||||
def get(self, request):
|
||||
# if not request.user.has_plan(self.plan_name):
|
||||
# return render(request, "denied.html")
|
||||
if request.user.is_anonymous:
|
||||
sizes = settings.OPENSEARCH_MAIN_SIZES_ANON
|
||||
else:
|
||||
@@ -60,16 +60,15 @@ class Drilldown(View):
|
||||
}
|
||||
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):
|
||||
# if not request.user.has_plan(self.plan_name):
|
||||
# return HttpResponseForbidden()
|
||||
|
||||
template_name = "ui/drilldown/results.html"
|
||||
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)
|
||||
if "message" in context:
|
||||
return render(request, self.template_name, context)
|
||||
@@ -86,7 +85,9 @@ class DrilldownSearch(View):
|
||||
]
|
||||
)
|
||||
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:
|
||||
return HttpResponse("No results")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user