From da235fedd6ec1709f70a7d18464aaa199c842074 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 27 Jul 2022 08:58:57 +0100 Subject: [PATCH] Implement editing networks --- core/lib/manage/threshold.py | 7 +++ .../threshold/irc/network/edit-network.html | 50 +++++++++++++++++-- core/views/dynamic/manage/threshold/irc.py | 14 +++++- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 7138be1..f3ab1fc 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -28,6 +28,13 @@ def get_irc_network(net): return network +def edit_irc_network(net, data): + url = f"irc/network/{net}/edit" + payload = dict(data) + network = threshold_request(url, payload) + return network + + def get_irc_relays(net): url = f"irc/network/{net}/relays" payload = {} diff --git a/core/templates/dynamic/manage/threshold/irc/network/edit-network.html b/core/templates/dynamic/manage/threshold/irc/network/edit-network.html index d01e2f9..a7f8f29 100644 --- a/core/templates/dynamic/manage/threshold/irc/network/edit-network.html +++ b/core/templates/dynamic/manage/threshold/irc/network/edit-network.html @@ -1,8 +1,8 @@
+ hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' + hx-post="{% url 'threshold_irc_network_edit' net %}" + hx-target="this" + hx-swap="outerHTML">
@@ -15,7 +15,47 @@ hx-swap="outerHTML"> diff --git a/core/views/dynamic/manage/threshold/irc.py b/core/views/dynamic/manage/threshold/irc.py index 287e9e5..8353cd9 100644 --- a/core/views/dynamic/manage/threshold/irc.py +++ b/core/views/dynamic/manage/threshold/irc.py @@ -4,6 +4,7 @@ from rest_framework.parsers import FormParser from rest_framework.views import APIView from core.lib.manage.threshold import ( + edit_irc_network, get_irc_channels, get_irc_network, get_irc_networks, @@ -62,9 +63,18 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView): Returns the info pane with a message about the success. """ template_name = "dynamic/manage/threshold/irc/network/info.html" + edited = edit_irc_network(net, request.data) + if edited["success"]: + message = "Successfully edited!" + message_class = "success" + else: + if "reason" in edited: + message = f"Error editing network: {edited['reason']}" + else: + message = "Error editing network" + message_class = "danger" network = get_irc_network(net) - context = {"network": network, "message": "Edited!", "class": "info"} - print("REQUEST DATA", net, request.data) + context = {"network": network, "message": message, "class": message_class} return render(request, template_name, context)
{{ key }}
- + {% if key == 'auth' %} +
+ +
+ {% elif key == 'security' %} +
+ +
+ {% else %} + + {% endif %}