mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Misc cleanup
This commit is contained in:
parent
c2416411c1
commit
f664998d9b
@ -9,18 +9,15 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models import ManyToManyField
|
from django.db.models import ManyToManyField
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from rest_framework import mixins
|
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.permissions import BasePermission
|
from rest_framework.permissions import BasePermission
|
||||||
from rest_framework.relations import PrimaryKeyRelatedField
|
from rest_framework.relations import PrimaryKeyRelatedField
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import Field, ModelSerializer, RelatedField, ValidationError
|
from rest_framework.serializers import Field, ModelSerializer, RelatedField, ValidationError
|
||||||
from rest_framework.viewsets import GenericViewSet, ViewSet
|
from rest_framework.viewsets import ModelViewSet as _ModelViewSet, ViewSet
|
||||||
|
|
||||||
from .utils import dynamic_import
|
from .utils import dynamic_import
|
||||||
|
|
||||||
WRITE_OPERATIONS = ['create', 'update', 'partial_update', 'delete']
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceUnavailable(APIException):
|
class ServiceUnavailable(APIException):
|
||||||
status_code = 503
|
status_code = 503
|
||||||
@ -188,19 +185,16 @@ class WritableNestedSerializer(ModelSerializer):
|
|||||||
# Viewsets
|
# Viewsets
|
||||||
#
|
#
|
||||||
|
|
||||||
class ModelViewSet(mixins.CreateModelMixin,
|
class ModelViewSet(_ModelViewSet):
|
||||||
mixins.RetrieveModelMixin,
|
|
||||||
mixins.UpdateModelMixin,
|
|
||||||
mixins.DestroyModelMixin,
|
|
||||||
mixins.ListModelMixin,
|
|
||||||
GenericViewSet):
|
|
||||||
"""
|
"""
|
||||||
Accept either a single object or a list of objects to create.
|
Accept either a single object or a list of objects to create.
|
||||||
"""
|
"""
|
||||||
def get_serializer(self, *args, **kwargs):
|
def get_serializer(self, *args, **kwargs):
|
||||||
|
|
||||||
# If a list of objects has been provided, initialize the serializer with many=True
|
# If a list of objects has been provided, initialize the serializer with many=True
|
||||||
if isinstance(kwargs.get('data', {}), list):
|
if isinstance(kwargs.get('data', {}), list):
|
||||||
kwargs['many'] = True
|
kwargs['many'] = True
|
||||||
|
|
||||||
return super(ModelViewSet, self).get_serializer(*args, **kwargs)
|
return super(ModelViewSet, self).get_serializer(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user