From 8b7dffa1b4b9a5c9d0a73a8a5dad1c07d20a4e97 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 14 Aug 2022 22:58:29 +0100 Subject: [PATCH] Fix issues with POST/GET arguments and the modal --- core/templates/ui/drilldown/drilldown.html | 5 ++++- .../ui/drilldown/table_results_partial.html | 4 +++- core/templatetags/urlsafe.py | 9 +++++++++ core/views/manage/threshold/irc.py | 17 +++++++++++++---- core/views/ui/drilldown.py | 7 +++++++ 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 core/templatetags/urlsafe.py diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index e19730d..aa19f5b 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -13,7 +13,10 @@ "channel": "{{ params.channel|escapejs }}", "time": "{{ params.time|escapejs }}", "date": "{{ params.date|escapejs }}", - "index": "{{ params.index }}"}' + "index": "{{ params.index }}", + "type": "{{ params.type|escapejs }}", + "mtype": "{{ params.mtype|escapejs }}", + "nick": "{{ params.nick|escapejs }}",}' hx-target="#modals-here" hx-trigger="load"> diff --git a/core/templates/ui/drilldown/table_results_partial.html b/core/templates/ui/drilldown/table_results_partial.html index fdd7a10..b2169b1 100644 --- a/core/templates/ui/drilldown/table_results_partial.html +++ b/core/templates/ui/drilldown/table_results_partial.html @@ -3,6 +3,7 @@ {% load django_tables2_bulma_template %} {% load static %} {% load joinsep %} +{% load urlsafe %} {% block table-wrapper %}
{% block table %} @@ -233,7 +234,8 @@ "mtype": "{{ row.cells.mtype }}", "nick": "{{ row.cells.nick|escapejs }}"}' hx-target="#modals-here" - hx-trigger="click"> + hx-trigger="click" + href="/?modal=context&net={{row.cells.net|escapejs}}&num={{row.cells.num|escapejs}}&src={{row.cells.src|escapejs}}&channel={{row.cells.channel|urlsafe}}&time={{row.cells.time|escapejs}}&date={{row.cells.date|escapejs}}&index={{params.index}}&type={{row.cells.type}}&mtype={{row.cells.mtype}}&nick={{row.cells.mtype|escapejs}}"> {{ row.cells.msg }} diff --git a/core/templatetags/urlsafe.py b/core/templatetags/urlsafe.py new file mode 100644 index 0000000..602d997 --- /dev/null +++ b/core/templatetags/urlsafe.py @@ -0,0 +1,9 @@ +import urllib.parse +from django import template + +register = template.Library() + + +@register.filter +def urlsafe(h): + return urllib.parse.quote(h, safe="") diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index 3f854cc..c59fb54 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -438,12 +438,15 @@ class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView): if not updated["success"]: message = updated["reason"] message_class = "danger" - + unreg = threshold.irc_get_unreg(net) context = { - "net": net, + "unreg": unreg, "message": message, "class": message_class, } + if net: + if net != "None": + context["net"] = net return render(request, template_name, context) @@ -463,13 +466,19 @@ class ThresholdIRCActionsRegistrationAuth(SuperUserRequiredMixin, APIView): if not updated["success"]: message = updated["reason"] message_class = "danger" - + if "net" in request.data: + net = request.data["net"] + else: + net = None + unreg = threshold.irc_get_unreg(net) context = { + "unreg": unreg, "message": message, "class": message_class, } if "net" in request.data: - context["net"] = request.data["net"] + if request.data["net"] != "None": + context["net"] = request.data["net"] return render(request, self.template_name, context) diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index f8c9357..cc61a12 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -96,6 +96,13 @@ def drilldown_search(request, return_context=False, template=None): context = {"sizes": sizes} return render(request, template_name, context) + tmp_post = request.POST.dict() + tmp_get = request.GET.dict() + tmp_post = {k: v for k, v in tmp_post.items() if v and not v == "None"} + tmp_get = {k: v for k, v in tmp_get.items() if v and not v == "None"} + query_params.update(tmp_post) + query_params.update(tmp_get) + if "index" in query_params: if not request.user.is_superuser: message = "You can't use the index parameter"