From 362ad579d5e2a8741083bad1d1c40faa5a959f43 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 29 Jul 2022 22:22:22 +0100 Subject: [PATCH] Implement aliases --- app/urls.py | 12 ++++++ core/lib/manage/threshold.py | 7 ++++ core/lib/threshold.py | 21 ++++++++-- .../manage/threshold/irc/network/actions.html | 34 +++++++++++++++ .../threshold/irc/network/edit-network.html | 2 +- .../manage/threshold/irc/network/network.html | 21 ++++++++-- .../threshold/irc/overview/aliases.html | 41 +++++++++++++++++++ .../threshold/irc/overview/overview.html | 15 +++++-- core/templatetags/joinsep.py | 8 ++++ core/views/manage/threshold/irc.py | 32 +++++++++++++-- 10 files changed, 178 insertions(+), 15 deletions(-) create mode 100644 core/templates/manage/threshold/irc/network/actions.html create mode 100644 core/templates/manage/threshold/irc/overview/aliases.html create mode 100644 core/templatetags/joinsep.py diff --git a/app/urls.py b/app/urls.py index 02b7110..13c8eed 100644 --- a/app/urls.py +++ b/app/urls.py @@ -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//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"), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 422cd30..61f1ba3 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -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 diff --git a/core/lib/threshold.py b/core/lib/threshold.py index 954dd37..ba1c94b 100644 --- a/core/lib/threshold.py +++ b/core/lib/threshold.py @@ -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}) diff --git a/core/templates/manage/threshold/irc/network/actions.html b/core/templates/manage/threshold/irc/network/actions.html new file mode 100644 index 0000000..3df22cf --- /dev/null +++ b/core/templates/manage/threshold/irc/network/actions.html @@ -0,0 +1,34 @@ +
+
+ + + +
+
\ No newline at end of file diff --git a/core/templates/manage/threshold/irc/network/edit-network.html b/core/templates/manage/threshold/irc/network/edit-network.html index a7f8f29..e88daf4 100644 --- a/core/templates/manage/threshold/irc/network/edit-network.html +++ b/core/templates/manage/threshold/irc/network/edit-network.html @@ -67,7 +67,7 @@ diff --git a/core/templates/manage/threshold/irc/network/network.html b/core/templates/manage/threshold/irc/network/network.html index 2c0c72e..30fb4c5 100644 --- a/core/templates/manage/threshold/irc/network/network.html +++ b/core/templates/manage/threshold/irc/network/network.html @@ -4,7 +4,7 @@
@@ -22,12 +22,21 @@
+
+
+
@@ -58,7 +67,7 @@
-
+
@@ -89,5 +98,11 @@
+
+
+
+
+
+
{% endblock %} diff --git a/core/templates/manage/threshold/irc/overview/aliases.html b/core/templates/manage/threshold/irc/overview/aliases.html new file mode 100644 index 0000000..ff2f050 --- /dev/null +++ b/core/templates/manage/threshold/irc/overview/aliases.html @@ -0,0 +1,41 @@ +{% load joinsep %} + +
+ {% if message is not None %} +
+ {{ message }} +
+ {% endif %} + {% if aliases is not None %} +
+
+ + + + + + + + + {% for alias in aliases %} + + + + + + + {% endfor %} + +
numnickrealnameemails
+ {{ alias.num }} + + {{ alias.nick }} + + {{ alias.realname }} + + {{ alias.emails|joinsep:', ' }} +
+
+
+ {% endif %} +
\ No newline at end of file diff --git a/core/templates/manage/threshold/irc/overview/overview.html b/core/templates/manage/threshold/irc/overview/overview.html index 7dbf810..6428521 100644 --- a/core/templates/manage/threshold/irc/overview/overview.html +++ b/core/templates/manage/threshold/irc/overview/overview.html @@ -4,7 +4,7 @@
@@ -13,12 +13,21 @@
+
+
+
@@ -37,7 +46,7 @@
-
+
diff --git a/core/templatetags/joinsep.py b/core/templatetags/joinsep.py new file mode 100644 index 0000000..4f0c06b --- /dev/null +++ b/core/templatetags/joinsep.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter +def joinsep(lst, sep): + return sep.join(lst) diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index 2e50961..a199f6b 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -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) \ No newline at end of file