from django.shortcuts import render from django.views import View from rest_framework.parsers import FormParser from rest_framework.views import APIView from core.lib.manage.threshold import ( get_irc_channels, get_irc_network, get_irc_networks, get_irc_relays, get_irc_stats, ) from core.views.manage.permissions import SuperUserRequiredMixin class ThresholdIRCStats(SuperUserRequiredMixin, View): stats_template = "dynamic/manage/threshold/irc/overview/stats.html" def post(self, request): stats = get_irc_stats() context = {"stats": stats} return render(request, self.stats_template, context) class ThresholdIRCNetworks(SuperUserRequiredMixin, View): template_name = "dynamic/manage/threshold/irc/overview/networks.html" def post(self, request): networks = get_irc_networks() context = {"networks": networks} return render(request, self.template_name, context) class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View): template_name = "dynamic/manage/threshold/irc/network/info.html" def post(self, request, net): network = get_irc_network(net) context = {"network": network} return render(request, self.template_name, context) class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView): template_name = "dynamic/manage/threshold/irc/network/edit-network.html" parser_classes = [FormParser] def get(self, request, net): """ Return the form to edit a network. """ network = get_irc_network(net) editable = ["auth", "host", "last", "port", "security"] context = { "net": net, "network": {k: v for k, v in network.items() if k in editable}, } return render(request, self.template_name, context) def post(self, request, net): """ Actually edit the network. Returns the info pane with a message about the success. """ template_name = "dynamic/manage/threshold/irc/network/info.html" network = get_irc_network(net) context = {"network": network, "message": "Edited!", "class": "info"} print("REQUEST DATA", net, request.data) return render(request, template_name, context) class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View): template_name = "dynamic/manage/threshold/irc/network/relays.html" def post(self, request, net): relays = get_irc_relays(net) context = {"relays": relays["relays"]} return render(request, self.template_name, context) class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View): template_name = "dynamic/manage/threshold/irc/network/channels.html" def post(self, request, net): channels = get_irc_channels(net) context = {"channels": channels["channels"]} return render(request, self.template_name, context)