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

@ -1,8 +1,8 @@
<form <form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_edit' net %}" hx-post="{% url 'threshold_irc_network_edit' net %}"
hx-target="this" hx-target="this"
hx-swap="outerHTML"> hx-swap="outerHTML">
<div class="table-container"> <div class="table-container">
<table class="table is-fullwidth is-hoverable"> <table class="table is-fullwidth is-hoverable">
<thead> <thead>
@ -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>

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

Loading…
Cancel
Save