Only parse dates if the field is valid

This commit is contained in:
Mark Veidemanis 2022-08-09 07:20:30 +01:00
parent 648526a6bf
commit 16c03bc19a
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 7 additions and 12 deletions

View File

@ -34,10 +34,8 @@ class DrilldownTableView(View, SingleTableMixin):
return render(request, self.template_name, context) return render(request, self.template_name, context)
if self.request.htmx: if self.request.htmx:
print("IS HTMX")
template_name = "ui/drilldown/table_results.html" template_name = "ui/drilldown/table_results.html"
else: else:
print("IS NOT HTMX")
template_name = "ui/drilldown/table_results_partial.html" template_name = "ui/drilldown/table_results_partial.html"
if context: if context:
@ -64,10 +62,6 @@ def parse_dates(dates):
"from_time": from_time, "from_time": from_time,
"to_time": to_time, "to_time": to_time,
} }
else:
message = "Invalid dates"
message_class = "danger"
return {"message": message, "class": message_class}
def create_tags(query): def create_tags(query):
@ -92,12 +86,13 @@ def drilldown_search(request):
if "dates" in query_params: if "dates" in query_params:
dates = parse_dates(query_params["dates"]) dates = parse_dates(query_params["dates"])
del query_params["dates"] del query_params["dates"]
if "message" in dates: if dates:
return render(request, template_name, dates) if "message" in dates:
query_params["from_date"] = dates["from_date"] return render(request, template_name, dates)
query_params["to_date"] = dates["to_date"] query_params["from_date"] = dates["from_date"]
query_params["from_time"] = dates["from_time"] query_params["to_date"] = dates["to_date"]
query_params["to_time"] = dates["to_time"] query_params["from_time"] = dates["from_time"]
query_params["to_time"] = dates["to_time"]
if request.GET: if request.GET:
context = query_results(request, query_params) context = query_results(request, query_params)