Implement editing networks

modern-tables
Mark Veidemanis 2 years ago
parent e3f4c72ce2
commit da235fedd6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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 = {}

@ -1,8 +1,8 @@
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_edit' net %}"
hx-target="this"
hx-swap="outerHTML">
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_edit' net %}"
hx-target="this"
hx-swap="outerHTML">
<div class="table-container">
<table class="table is-fullwidth is-hoverable">
<thead>
@ -15,7 +15,47 @@ hx-swap="outerHTML">
<th>{{ key }}</th>
<td>
<div class="field">
<input type="text" name="{{ key }}" value="{{ item }}">
{% if key == 'auth' %}
<div class="select">
<select name="{{ key }}">
{% if item == 'sasl' %}
<option selected>sasl</option>
{% else %}
<option>sasl</option>
{% endif %}
{% if item == 'ns' %}
<option selected>ns</option>
{% else %}
<option>ns</option>
{% endif %}
{% if item == 'none' %}
<option selected>none</option>
{% else %}
<option>none</option>
{% endif %}
</select>
</div>
{% elif key == 'security' %}
<div class="select">
<select name="{{ key }}">
{% if item == 'ssl' %}
<option selected>ssl</option>
{% else %}
<option>ssl</option>
{% endif %}
{% if item == 'plain' %}
<option selected>plain</option>
{% else %}
<option>plain</option>
{% endif %}
</select>
</div>
{% else %}
<input class="input" type="text" name="{{ key }}" value="{{ item }}">
{% endif %}
</div>
</td>
</tr>

@ -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)

Loading…
Cancel
Save