Implement aliases

This commit is contained in:
Mark Veidemanis 2022-07-29 22:22:22 +01:00
parent 755bc66844
commit 362ad579d5
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
10 changed files with 178 additions and 15 deletions

View File

@ -31,6 +31,8 @@ from core.views.manage.threshold.irc import (
ThresholdIRCNetworkRelayStatus, ThresholdIRCNetworkRelayStatus,
ThresholdIRCNetworks, ThresholdIRCNetworks,
ThresholdIRCStats, ThresholdIRCStats,
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
) )
# Management stuff # Management stuff
@ -141,6 +143,16 @@ urlpatterns = [
ThresholdIRCNetworkChannels.as_view(), ThresholdIRCNetworkChannels.as_view(),
name="threshold_irc_network_channel", 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/chans/", ThresholdChans.as_view(), name="chans"),
path("api/users/", ThresholdUsers.as_view(), name="users"), path("api/users/", ThresholdUsers.as_view(), name="users"),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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