toolshed/backend/hostadmin/api.py

61 lines
2.1 KiB
Python
Raw Permalink Normal View History

2023-10-22 20:46:55 +00:00
from rest_framework import routers, viewsets
2023-06-15 18:55:33 +00:00
from rest_framework.authentication import TokenAuthentication
2023-10-22 20:46:55 +00:00
from rest_framework.permissions import IsAuthenticated, IsAdminUser
2023-06-15 18:55:33 +00:00
2023-10-22 20:46:55 +00:00
from authentication.signature_auth import SignatureAuthenticationLocal
2023-06-15 18:55:33 +00:00
from hostadmin.models import Domain
2023-10-22 20:46:55 +00:00
from hostadmin.serializers import DomainSerializer, CategorySerializer, PropertySerializer, TagSerializer
from toolshed.models import Category, Property, Tag
2023-06-15 18:55:33 +00:00
router = routers.SimpleRouter()
class DomainViewSet(viewsets.ModelViewSet):
queryset = Domain.objects.all()
serializer_class = DomainSerializer
2023-10-22 20:46:55 +00:00
authentication_classes = [TokenAuthentication, SignatureAuthenticationLocal]
permission_classes = [IsAuthenticated, IsAdminUser]
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class CategoryViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
authentication_classes = [TokenAuthentication, SignatureAuthenticationLocal]
permission_classes = [IsAuthenticated, IsAdminUser]
def perform_create(self, serializer):
serializer.save(origin='api')
class PropertyViewSet(viewsets.ModelViewSet):
queryset = Property.objects.all()
serializer_class = PropertySerializer
authentication_classes = [TokenAuthentication, SignatureAuthenticationLocal]
permission_classes = [IsAuthenticated, IsAdminUser]
def perform_create(self, serializer):
serializer.save(origin='api')
class TagViewSet(viewsets.ModelViewSet):
queryset = Tag.objects.all()
serializer_class = TagSerializer
authentication_classes = [TokenAuthentication, SignatureAuthenticationLocal]
permission_classes = [IsAuthenticated, IsAdminUser]
def perform_create(self, serializer):
serializer.save(origin='api')
2023-06-15 18:55:33 +00:00
router.register(r'domains', DomainViewSet, basename='domains')
2023-10-22 20:46:55 +00:00
router.register(r'categories', CategoryViewSet, basename='categories')
router.register(r'properties', PropertyViewSet, basename='properties')
router.register(r'tags', TagViewSet, basename='tags')
2023-06-15 18:55:33 +00:00
urlpatterns = [
*router.urls,
]