diff --git a/core/api/views/threshold.py b/core/api/views/threshold.py index 68681f7..fc7b508 100644 --- a/core/api/views/threshold.py +++ b/core/api/views/threshold.py @@ -6,7 +6,13 @@ from django.shortcuts import render from rest_framework.parsers import FormParser from rest_framework.views import APIView -from core.lib.threshold import annotate_online, get_chans, get_users +from core.lib.threshold import ( + annotate_num_chans, + annotate_num_users, + annotate_online, + get_chans, + get_users, +) logger = logging.getLogger(__name__) @@ -87,6 +93,8 @@ class ThresholdInfoModal(LoginRequiredMixin, APIView): channel = request.data["channel"] channels = get_chans(net, [nick]) users = get_users(net, [channel]) + num_users = annotate_num_users(net, channels) + num_chans = annotate_num_chans(net, users) if channels: inter_users = get_users(net, channels) else: @@ -103,5 +111,7 @@ class ThresholdInfoModal(LoginRequiredMixin, APIView): "users": users, "inter_chans": inter_chans, "inter_users": inter_users, + "num_users": num_users, + "num_chans": num_chans, } return render(request, self.template_name, context) diff --git a/core/lib/threshold.py b/core/lib/threshold.py index 66984f6..e2e9bbd 100644 --- a/core/lib/threshold.py +++ b/core/lib/threshold.py @@ -50,9 +50,10 @@ def threshold_request(url, data): return False try: response = r.json() + sort_data(response) except JSONDecodeError: logging.error(f"Invalid JSON response: {r.text}") - sort_data(response) + return False return response @@ -81,3 +82,21 @@ def annotate_online(net, query): if not online_info: return {} return online_info + + +def annotate_num_users(net, query): + url = "num_users" + payload = {"net": net, "query": query} + user_num_map = threshold_request(url, payload) + if not user_num_map: + return {} + return user_num_map + + +def annotate_num_chans(net, query): + url = "num_chans" + payload = {"net": net, "query": query} + chan_num_map = threshold_request(url, payload) + if not chan_num_map: + return {} + return chan_num_map diff --git a/core/templates/modals/info.html b/core/templates/modals/info.html index a5d5224..a90892c 100644 --- a/core/templates/modals/info.html +++ b/core/templates/modals/info.html @@ -1,3 +1,5 @@ +{% load index %} +