Beispiel #1
0
 def get(self, request, node_type):
     if node_type == "vmess":
         form = VmessNodeForm()
     elif node_type == "ss":
         form = SSNodeForm()
     return render(request,
                   "my_admin/node_detail.html",
                   context={"form": form})
Beispiel #2
0
    def get(self, request, node_type, node_id):
        if node_type == "vmess":
            vmess_node = VmessNode.objects.get(node_id=node_id)
            form = VmessNodeForm(instance=vmess_node)
        elif node_type == "ss":
            ss_node = SSNode.objects.get(node_id=node_id)
            form = SSNodeForm(instance=ss_node)

        return render(request,
                      "my_admin/node_detail.html",
                      context={"form": form})
    def post(self, request, node_type):
        if node_type == "vmess":
            form = VmessNodeForm(request.POST)
        elif node_type == "ss":
            form = SSNodeForm(request.POST)
        elif node_type == "trojan":
            form = TrojanNodeForm(request.POST)

        if form.is_valid():
            form.save()
            messages.success(request, "数据更新成功!", extra_tags="添加成功")
            return HttpResponseRedirect(reverse("sspanel:admin_node_list"))
        else:
            messages.error(request, "数据填写错误", extra_tags="错误")
            context = {"form": form}
            return render(request,
                          "my_admin/node_detail.html",
                          context=context)
    def post(self, request, node_type, node_id):
        if node_type == "vmess":
            node = VmessNode.objects.get(node_id=node_id)
            form = VmessNodeForm(request.POST, instance=node)
        elif node_type == "ss":
            node = SSNode.objects.get(node_id=node_id)
            form = SSNodeForm(request.POST, instance=node)
        elif node_type == "trojan":
            node = TrojanNode.objects.get(node_id=node_id)
            form = TrojanNodeForm(request.POST, instance=node)

        if form.is_valid():
            form.save()
            messages.success(request, "数据更新成功", extra_tags="修改成功")
            return HttpResponseRedirect(reverse("sspanel:admin_node_list"))
        else:
            messages.error(request, "数据填写错误", extra_tags="错误")
            return render(request,
                          "my_admin/node_detail.html",
                          context={"form": form})