Replace AtomicMixin with mixins subclasses.
parent
7d2d047177
commit
487a50b900
|
@ -10,25 +10,31 @@ from rest_framework.response import Response
|
||||||
from .pagination import HeadersPaginationMixin, ConditionalPaginationMixin
|
from .pagination import HeadersPaginationMixin, ConditionalPaginationMixin
|
||||||
|
|
||||||
|
|
||||||
class AtomicMixin(object):
|
class CreateModelMixin(mixins.CreateModelMixin):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def post(self, *args, **kwargs):
|
def create(self, *args, **kwargs):
|
||||||
return super().post(*args, **kwargs)
|
return super().create(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class RetrieveModelMixin(mixins.RetrieveModelMixin):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def delete(self, *args, **kwargs):
|
def retrieve(self, *args, **kwargs):
|
||||||
return super().delete(*args, **kwargs)
|
return super().retrieve(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateModelMixin(mixins.UpdateModelMixin):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def put(self, *args, **kwargs):
|
def update(self, *args, **kwargs):
|
||||||
return super().put(*args, **kwargs)
|
return super().update(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ListModelMixin(mixins.ListModelMixin):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def patch(self, *args, **kwargs):
|
def list(self, *args, **kwargs):
|
||||||
return super().patch(*args, **kwargs)
|
return super().list(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class DestroyModelMixin(object):
|
class DestroyModelMixin(mixins.DestroyModelMixin):
|
||||||
"""
|
"""
|
||||||
Self version of DestroyModelMixin with
|
Self version of DestroyModelMixin with
|
||||||
pre_delete hook method.
|
pre_delete hook method.
|
||||||
|
@ -37,6 +43,7 @@ class DestroyModelMixin(object):
|
||||||
def pre_delete(self, obj):
|
def pre_delete(self, obj):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
self.pre_delete(obj)
|
self.pre_delete(obj)
|
||||||
|
@ -72,24 +79,24 @@ class DetailAndListSerializersMixin(object):
|
||||||
return super().get_serializer_class()
|
return super().get_serializer_class()
|
||||||
|
|
||||||
|
|
||||||
class ModelCrudViewSet(AtomicMixin,
|
class ModelCrudViewSet(DetailAndListSerializersMixin,
|
||||||
DetailAndListSerializersMixin,
|
|
||||||
PreconditionMixin,
|
PreconditionMixin,
|
||||||
HeadersPaginationMixin,
|
HeadersPaginationMixin,
|
||||||
ConditionalPaginationMixin,
|
ConditionalPaginationMixin,
|
||||||
mixins.CreateModelMixin,
|
CreateModelMixin,
|
||||||
mixins.RetrieveModelMixin,
|
RetrieveModelMixin,
|
||||||
mixins.UpdateModelMixin,
|
UpdateModelMixin,
|
||||||
DestroyModelMixin,
|
DestroyModelMixin,
|
||||||
mixins.ListModelMixin,
|
ListModelMixin,
|
||||||
viewsets.GenericViewSet):
|
viewsets.GenericViewSet):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ModelListViewSet(AtomicMixin,
|
class ModelListViewSet(DetailAndListSerializersMixin,
|
||||||
DetailAndListSerializersMixin,
|
|
||||||
PreconditionMixin,
|
PreconditionMixin,
|
||||||
HeadersPaginationMixin,
|
HeadersPaginationMixin,
|
||||||
ConditionalPaginationMixin,
|
ConditionalPaginationMixin,
|
||||||
viewsets.ReadOnlyModelViewSet):
|
RetrieveModelMixin,
|
||||||
|
ListModelMixin,
|
||||||
|
viewsets.GenericViewSet):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue