Implement adding relays by number

modern-tables
Mark Veidemanis 2 years ago
parent dc293b0dbc
commit 0457cfbbed
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -24,6 +24,9 @@ from core.api.views.threshold import ThresholdChans, ThresholdOnline, ThresholdU
from core.views import Billing, Cancel, Home, Order, Portal, Signup
from core.views.callbacks import Callback
from core.views.manage.threshold.irc import (
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
ThresholdIRCNetworkActionsAddRelay,
ThresholdIRCNetworkChannels,
ThresholdIRCNetworkInfo,
ThresholdIRCNetworkInfoEdit,
@ -31,8 +34,6 @@ from core.views.manage.threshold.irc import (
ThresholdIRCNetworkRelayStatus,
ThresholdIRCNetworks,
ThresholdIRCStats,
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
)
# Management stuff
@ -153,6 +154,11 @@ urlpatterns = [
ThresholdIRCNetworkActions.as_view(),
name="threshold_irc_network_actions",
),
path(
"manage/threshold/irc/network/actions/<str:net>/",
ThresholdIRCNetworkActionsAddRelay.as_view(),
name="threshold_irc_network_actions_add_relay",
),
##
path("api/chans/", ThresholdChans.as_view(), name="chans"),
path("api/users/", ThresholdUsers.as_view(), name="users"),

@ -81,9 +81,16 @@ def join_channel(net, channel):
return {}
return joined
def get_aliases():
url = "aliases"
payload = {}
aliases = threshold_request(url, payload, method="GET")
print("Aliases", aliases)
return aliases
def add_relay(net, num):
url = f"irc/network/{net}/{num}"
payload = {}
created = threshold_request(url, payload, method="PUT")
return created

@ -1,13 +1,21 @@
<div id="actions">
{% if message is not None %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-trigger="click"
hx-target="#channels"
hx-swap="outerHTML"
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Add relay</span>
<span>Relay</span>
</span>
</button>
<button
@ -17,7 +25,7 @@
<span class="icon">
<i class="fa-solid fa-wrench"></i>
</span>
<span>Run auto</span>
<span>Auto</span>
</span>
</button>
<button
@ -27,8 +35,40 @@
<span class="icon">
<i class="fa-solid fa-list"></i>
</span>
<span>Request list</span>
<span>List</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-list"></i>
</span>
<span>Registration</span>
</span>
</button>
</div>
<form method="POST">
<div class="field has-addons">
<div class="control is-expanded has-icons-left">
<input class="input" name="num" type="text" placeholder="Relay number">
<span class="icon is-small is-left">
<i class="fa-brands fa-unity"></i>
</span>
</div>
<div class="control">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button is-primary is-fullwidth"
hx-put="{% url 'threshold_irc_network_actions_add_relay' net %}"
hx-trigger="click"
hx-target="#actions"
hx-swap="outerHTML">
Add
</button>
</div>
</div>
</form>
</div>

@ -29,13 +29,13 @@
</div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_network_actions' net %}"
hx-trigger="load"
hx-target="#actions"
hx-swap="outerHTML">
</div>
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_network_actions' net %}"
hx-trigger="load"
hx-target="#actions"
hx-swap="outerHTML">
</div>
<div class="columns">
<div class="column">
@ -62,27 +62,24 @@
<div class="column">
<div class="box">
<div id="alerts">
Alerts here
</div>
</div>
</div>
</div>
<div class="columns">
<div class="column">
{# This is the only thing included without HTMX because it isn't interactive #}
{# It needs no dynamic message element because it posts messages to chanels #}
<div class="box">
<form method="POST">
<div class="field">
<div class="field-body">
<div class="field">
<div class="control is-expanded has-icons-left">
<input id="query" name="channel" class="input" type="text" placeholder="channel">
<span class="icon is-small is-left">
<i class="fa-solid fa-hashtag"></i>
</span>
</div>
</div>
<div class="field has-addons">
<div class="control is-expanded has-icons-left">
<input id="query" name="channel" class="input" type="text" placeholder="channel">
<span class="icon is-small is-left">
<i class="fa-solid fa-hashtag"></i>
</span>
</div>
</div>
<div class="field">
<div class="control">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'

@ -20,13 +20,13 @@
</div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_aliases' %}"
hx-trigger="load"
hx-target="#aliases"
hx-swap="outerHTML">
</div>
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_aliases' %}"
hx-trigger="load"
hx-target="#aliases"
hx-swap="outerHTML">
</div>
<div class="columns">
<div class="column">

@ -132,7 +132,7 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
:param channel: channel name
"""
parted = threshold.part_channel(net, channel)
if parted:
if parted["success"]:
message = f"Requested part on relays: {', '.join(parted['relays'])}"
message_class = "success"
else:
@ -158,10 +158,9 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
message_class = "danger"
else:
channel = request.data["channel"]
print("CHANNEL", channel)
joined = threshold.join_channel(net, channel)
print("JOINED", joined)
if joined:
if joined["success"]:
message = f"Requested join on relay: {joined['relays']}"
message_class = "success"
else:
@ -191,6 +190,7 @@ class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
}
return render(request, self.template_name, context)
class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/network/actions.html"
@ -198,5 +198,43 @@ class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
"""
Get actions page.
"""
context = {"net": net}
return render(request, self.template_name, context)
class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/actions.html"
parser_classes = [FormParser]
def put(self, request, net):
"""
Create a relay
"""
print("ACTION PUT", request.data, net)
if "num" not in request.data:
message = "No num specified"
message_class = "danger"
else:
num = request.data["num"]
if not num.isdigit():
message = "Num is not an integer"
message_class = "danger"
else:
num = int(num)
created = threshold.add_relay(net, num)
print("CREATED", created)
if created["success"]:
id = created["id"]
alias = created["alias"]
message = f"Created new relay {id} with alias {alias}"
message_class = "success"
else:
message = created["reason"]
message_class = "danger"
return render(request, self.template_name)
context = {
"net": net,
"message": message,
"class": message_class,
}
return render(request, self.template_name, context)

Loading…
Cancel
Save