Implement form for editing network
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
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,
|
||||
@@ -38,6 +40,34 @@ class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
|
||||
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"
|
||||
|
||||
@@ -54,3 +84,12 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View):
|
||||
channels = get_irc_channels(net)
|
||||
context = {"channels": channels["channels"]}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
||||
# CRUD stuff
|
||||
class ThresholdIRCNetworkEdit(SuperUserRequiredMixin, APIView):
|
||||
"""
|
||||
Edit a network's attributes.
|
||||
"""
|
||||
|
||||
parser_classes = [FormParser]
|
||||
|
||||
Reference in New Issue
Block a user