Implement aliases

modern-tables
Mark Veidemanis 2 years ago
parent 755bc66844
commit 362ad579d5
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -31,6 +31,8 @@ from core.views.manage.threshold.irc import (
ThresholdIRCNetworkRelayStatus,
ThresholdIRCNetworks,
ThresholdIRCStats,
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
)
# Management stuff
@ -141,6 +143,16 @@ urlpatterns = [
ThresholdIRCNetworkChannels.as_view(),
name="threshold_irc_network_channel",
),
path(
"manage/threshold/irc/aliases/",
ThresholdIRCAliases.as_view(),
name="threshold_irc_aliases",
),
path(
"manage/threshold/irc/network/<str:net>/actions/",
ThresholdIRCNetworkActions.as_view(),
name="threshold_irc_network_actions",
),
##
path("api/chans/", ThresholdChans.as_view(), name="chans"),
path("api/users/", ThresholdUsers.as_view(), name="users"),

@ -80,3 +80,10 @@ def join_channel(net, channel):
if not joined:
return {}
return joined
def get_aliases():
url = "aliases"
payload = {}
aliases = threshold_request(url, payload, method="GET")
print("Aliases", aliases)
return aliases

@ -26,13 +26,26 @@ def escape(obj):
def sort_data(data):
for item in data:
for item in data.keys():
if isinstance(data[item], list):
for v in data[item]:
if isinstance(v, list):
cont = True
if isinstance(v, dict):
cont = True
if cont:
continue
data[item].sort()
elif isinstance(data[item], dict):
# if all([isinstance(x, int) for k, v in
# data[item].items() for x in v.values()]):
# Don't sort nested stuff
cont = False
for k, v in data[item].items():
if isinstance(v, list):
cont = True
if isinstance(v, dict):
cont = True
if cont:
continue
sorted_item = sorted(data[item].items(), key=itemgetter(1), reverse=True)
data[item] = OrderedDict({k: v for k, v in sorted_item})

@ -0,0 +1,34 @@
<div id="actions">
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Add relay</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-wrench"></i>
</span>
<span>Run auto</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>Request list</span>
</span>
</button>
</div>
</div>

@ -67,7 +67,7 @@
<button
class="button is-primary"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_info' net %}">
hx-get="{% url 'threshold_irc_network_info' net %}">
Cancel
</button>
</div>

@ -4,7 +4,7 @@
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_info' net %}"
hx-get="{% url 'threshold_irc_network_info' net %}"
hx-trigger="load, every 5s"
hx-target="#info"
hx-swap="outerHTML">
@ -22,12 +22,21 @@
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_channels' net %}"
hx-get="{% url 'threshold_irc_network_channels' net %}"
hx-trigger="load, every 5s"
hx-target="#channels"
hx-swap="outerHTML">
</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>
<div class="columns">
<div class="column">
<div class="box">
@ -58,7 +67,7 @@
</div>
</div>
<div class="columns">
<div class="column is-half">
<div class="column">
<div class="box">
<form method="POST">
<div class="field">
@ -89,5 +98,11 @@
</form>
</div>
</div>
<div class="column">
<div class="box">
<div id="actions">
</div>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,41 @@
{% load joinsep %}
<div id="aliases">
{% if message is not None %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
{% if aliases is not None %}
<div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container">
<table class="table is-fullwidth is-hoverable">
<thead>
<th>num</th>
<th>nick</th>
<th>realname</th>
<th>emails</th>
</thead>
<tbody>
{% for alias in aliases %}
<tr>
<td>
{{ alias.num }}
</td>
<td>
{{ alias.nick }}
</td>
<td>
{{ alias.realname }}
</td>
<td>
{{ alias.emails|joinsep:', ' }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>

@ -4,7 +4,7 @@
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_stats' %}"
hx-get="{% url 'threshold_irc_stats' %}"
hx-trigger="load"
hx-target="#stats"
hx-swap="outerHTML">
@ -13,12 +13,21 @@
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_networks' %}"
hx-get="{% url 'threshold_irc_networks' %}"
hx-trigger="load"
hx-target="#networks"
hx-swap="outerHTML">
</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>
<div class="columns">
<div class="column">
<div class="box">
@ -37,7 +46,7 @@
<div class="columns">
<div class="column">
<div class="box">
<div id="channels">
<div id="aliases">
</div>
</div>
</div>

@ -0,0 +1,8 @@
from django import template
register = template.Library()
@register.filter
def joinsep(lst, sep):
return sep.join(lst)

@ -10,7 +10,7 @@ from core.views.manage.permissions import SuperUserRequiredMixin
class ThresholdIRCStats(SuperUserRequiredMixin, View):
stats_template = "manage/threshold/irc/overview/stats.html"
def post(self, request):
def get(self, request):
stats = threshold.get_irc_stats()
context = {"stats": stats}
return render(request, self.stats_template, context)
@ -19,7 +19,7 @@ class ThresholdIRCStats(SuperUserRequiredMixin, View):
class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/overview/networks.html"
def post(self, request):
def get(self, request):
networks = threshold.get_irc_networks()
context = {"networks": networks}
return render(request, self.template_name, context)
@ -28,7 +28,7 @@ class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/network/info.html"
def post(self, request, net):
def get(self, request, net):
network = threshold.get_irc_network(net)
context = {"network": network}
return render(request, self.template_name, context)
@ -116,7 +116,7 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/channels.html"
parser_classes = [FormParser]
def post(self, request, net):
def get(self, request, net):
"""
Get list of channels for network.
:param net: network name
@ -176,3 +176,27 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
"class": message_class,
}
return render(request, self.template_name, context)
class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/overview/aliases.html"
def get(self, request):
"""
Get aliases.
"""
aliases = threshold.get_aliases()
context = {
"aliases": aliases["aliases"],
}
return render(request, self.template_name, context)
class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/network/actions.html"
def get(self, request, net):
"""
Get actions page.
"""
return render(request, self.template_name)
Loading…
Cancel
Save