Refactor code into fewer files, removing dynamic folders
This commit is contained in:
96
core/views/manage/threshold/irc.py
Normal file
96
core/views/manage/threshold/irc.py
Normal file
@@ -0,0 +1,96 @@
|
||||
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 (
|
||||
edit_irc_network,
|
||||
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 = "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 = "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 = "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 = "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 = "manage/threshold/irc/network/info.html"
|
||||
edited = edit_irc_network(net, request.data)
|
||||
if edited["success"]:
|
||||
message = "Successfully edited!"
|
||||
message_class = "success"
|
||||
else:
|
||||
if "reason" in edited:
|
||||
message = f"Error editing network: {edited['reason']}"
|
||||
else:
|
||||
message = "Error editing network"
|
||||
message_class = "danger"
|
||||
network = get_irc_network(net)
|
||||
context = {"network": network, "message": message, "class": message_class}
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
|
||||
template_name = "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 = "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)
|
||||
19
core/views/manage/threshold/threshold.py
Normal file
19
core/views/manage/threshold/threshold.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
|
||||
from core.views.manage.permissions import SuperUserRequiredMixin
|
||||
|
||||
|
||||
class ThresholdIRCOverview(SuperUserRequiredMixin, View):
|
||||
template_name = "manage/threshold/irc/overview/overview.html"
|
||||
|
||||
def get(self, request):
|
||||
return render(request, self.template_name)
|
||||
|
||||
|
||||
class ThresholdIRCNetwork(SuperUserRequiredMixin, View):
|
||||
template_name = "manage/threshold/irc/network/network.html"
|
||||
|
||||
def get(self, request, net):
|
||||
context = {"net": net}
|
||||
return render(request, self.template_name, context)
|
||||
Reference in New Issue
Block a user