Implement editing networks

This commit is contained in:
Mark Veidemanis 2022-07-27 08:58:57 +01:00
parent e3f4c72ce2
commit da235fedd6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 64 additions and 7 deletions

View File

@ -28,6 +28,13 @@ def get_irc_network(net):
return network 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): def get_irc_relays(net):
url = f"irc/network/{net}/relays" url = f"irc/network/{net}/relays"
payload = {} payload = {}

View File

@ -15,7 +15,47 @@ hx-swap="outerHTML">
<th>{{ key }}</th> <th>{{ key }}</th>
<td> <td>
<div class="field"> <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> </div>
</td> </td>
</tr> </tr>

View File

@ -4,6 +4,7 @@ from rest_framework.parsers import FormParser
from rest_framework.views import APIView from rest_framework.views import APIView
from core.lib.manage.threshold import ( from core.lib.manage.threshold import (
edit_irc_network,
get_irc_channels, get_irc_channels,
get_irc_network, get_irc_network,
get_irc_networks, get_irc_networks,
@ -62,9 +63,18 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView):
Returns the info pane with a message about the success. Returns the info pane with a message about the success.
""" """
template_name = "dynamic/manage/threshold/irc/network/info.html" 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) network = get_irc_network(net)
context = {"network": network, "message": "Edited!", "class": "info"} context = {"network": network, "message": message, "class": message_class}
print("REQUEST DATA", net, request.data)
return render(request, template_name, context) return render(request, template_name, context)