123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- from __future__ import unicode_literals, print_function
- from rest_framework import mixins
- from rest_framework.generics import GenericAPIView
- from rest_framework.viewsets import ModelViewSet
- from . import mixins as bulk_mixins
- __all__ = [
- 'BulkCreateAPIView',
- 'BulkDestroyAPIView',
- 'BulkModelViewSet',
- 'BulkUpdateAPIView',
- 'ListBulkCreateAPIView',
- 'ListBulkCreateDestroyAPIView',
- 'ListBulkCreateUpdateAPIView',
- 'ListBulkCreateUpdateDestroyAPIView',
- 'ListCreateBulkUpdateAPIView',
- 'ListCreateBulkUpdateDestroyAPIView',
- ]
- # ################################################## #
- # Concrete view classes that provide method handlers #
- # by composing the mixin classes with the base view. #
- # ################################################## #
- class BulkCreateAPIView(bulk_mixins.BulkCreateModelMixin,
- GenericAPIView):
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- class BulkUpdateAPIView(bulk_mixins.BulkUpdateModelMixin,
- GenericAPIView):
- def put(self, request, *args, **kwargs):
- return self.bulk_update(request, *args, **kwargs)
- def patch(self, request, *args, **kwargs):
- return self.partial_bulk_update(request, *args, **kwargs)
- class BulkDestroyAPIView(bulk_mixins.BulkDestroyModelMixin,
- GenericAPIView):
- def delete(self, request, *args, **kwargs):
- return self.bulk_destroy(request, *args, **kwargs)
- class ListBulkCreateAPIView(mixins.ListModelMixin,
- bulk_mixins.BulkCreateModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- class ListCreateBulkUpdateAPIView(mixins.ListModelMixin,
- mixins.CreateModelMixin,
- bulk_mixins.BulkUpdateModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- def put(self, request, *args, **kwargs):
- return self.bulk_update(request, *args, **kwargs)
- def patch(self, request, *args, **kwargs):
- return self.partial_bulk_update(request, *args, **kwargs)
- class ListCreateBulkUpdateDestroyAPIView(mixins.ListModelMixin,
- mixins.CreateModelMixin,
- bulk_mixins.BulkUpdateModelMixin,
- bulk_mixins.BulkDestroyModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- def put(self, request, *args, **kwargs):
- return self.bulk_update(request, *args, **kwargs)
- def patch(self, request, *args, **kwargs):
- return self.partial_bulk_update(request, *args, **kwargs)
- def delete(self, request, *args, **kwargs):
- return self.bulk_destroy(request, *args, **kwargs)
- class ListBulkCreateUpdateAPIView(mixins.ListModelMixin,
- bulk_mixins.BulkCreateModelMixin,
- bulk_mixins.BulkUpdateModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- def put(self, request, *args, **kwargs):
- return self.bulk_update(request, *args, **kwargs)
- def patch(self, request, *args, **kwargs):
- return self.partial_bulk_update(request, *args, **kwargs)
- class ListBulkCreateDestroyAPIView(mixins.ListModelMixin,
- bulk_mixins.BulkCreateModelMixin,
- bulk_mixins.BulkDestroyModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- def delete(self, request, *args, **kwargs):
- return self.bulk_destroy(request, *args, **kwargs)
- class ListBulkCreateUpdateDestroyAPIView(mixins.ListModelMixin,
- bulk_mixins.BulkCreateModelMixin,
- bulk_mixins.BulkUpdateModelMixin,
- bulk_mixins.BulkDestroyModelMixin,
- GenericAPIView):
- def get(self, request, *args, **kwargs):
- return self.list(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- return self.create(request, *args, **kwargs)
- def put(self, request, *args, **kwargs):
- return self.bulk_update(request, *args, **kwargs)
- def patch(self, request, *args, **kwargs):
- return self.partial_bulk_update(request, *args, **kwargs)
- def delete(self, request, *args, **kwargs):
- return self.bulk_destroy(request, *args, **kwargs)
- # ########################################################## #
- # Concrete viewset classes that provide method handlers #
- # by composing the bulk mixin classes with the base viewset. #
- # ########################################################## #
- class BulkModelViewSet(bulk_mixins.BulkCreateModelMixin,
- bulk_mixins.BulkUpdateModelMixin,
- bulk_mixins.BulkDestroyModelMixin,
- ModelViewSet):
- pass
|