uncloud-mravi/uncloud_net/views.py

63 lines
1.9 KiB
Python
Raw Normal View History

2020-12-09 19:22:33 +00:00
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import render
from rest_framework import viewsets, permissions
from .models import *
from .serializers import *
from .selectors import *
from .forms import *
# class VPNPoolViewSet(viewsets.ModelViewSet):
# serializer_class = VPNPoolSerializer
# permission_classes = [permissions.IsAdminUser]
# queryset = VPNPool.objects.all()
# class VPNNetworkReservationViewSet(viewsets.ModelViewSet):
# serializer_class = VPNNetworkReservationSerializer
# permission_classes = [permissions.IsAdminUser]
# queryset = VPNNetworkReservation.objects.all()
2020-04-06 20:30:01 +00:00
2020-12-13 12:28:43 +00:00
class WireGuardVPNViewSet(viewsets.ModelViewSet):
serializer_class = WireGuardVPNSerializer
permission_classes = [permissions.IsAuthenticated]
2020-04-06 20:30:01 +00:00
2020-12-13 12:28:43 +00:00
def get_queryset(self):
if self.request.user.is_superuser:
obj = WireGuardVPN.objects.all()
else:
obj = WireGuardVPN.objects.filter(owner=self.request.user)
2020-12-13 12:28:43 +00:00
return obj
2020-12-09 19:22:33 +00:00
class WireGuardVPNCreateView(LoginRequiredMixin, SuccessMessageMixin, CreateView):
model = WireGuardVPN
2020-12-09 19:22:33 +00:00
login_url = '/login/'
success_url = '/'
success_message = "%(network) was created successfully"
2020-12-09 19:22:33 +00:00
form_class = WireGuardVPNForm
2020-12-09 19:22:33 +00:00
def get_success_message(self, cleaned_data):
return self.success_message % dict(cleaned_data,
the_prefix = self.object.prefix)
2020-12-13 12:28:43 +00:00
# def get_context_data(self, **kwargs):
# context = super().get_context_data(**kwargs)
# context['available_sizes'] = 2
# return context
# def post(request, *args, **kwargs):
# print(request)
# print(*args)
# print(*kwargs)
# def post(self, request, *args, **kwargs):