generics.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from __future__ import unicode_literals, print_function
  2. from rest_framework import mixins
  3. from rest_framework.generics import GenericAPIView
  4. from . import mixins as bulk_mixins
  5. __all__ = ["BulkCreateAPIView", "BulkUpdateAPIView", "BulkDestroyAPIView", "ListBulkCreateAPIView",
  6. "ListCreateBulkUpdateAPIView", "ListCreateBulkUpdateDestroyAPIView", "ListBulkCreateUpdateAPIView",
  7. "ListBulkCreateUpdateDestroyAPIView"]
  8. ##########################################################
  9. ### Concrete view classes that provide method handlers ###
  10. ### by composing the mixin classes with the base view. ###
  11. ##########################################################
  12. class BulkCreateAPIView(bulk_mixins.BulkCreateModelMixin,
  13. GenericAPIView):
  14. def post(self, request, *args, **kwargs):
  15. return self.create(request, *args, **kwargs)
  16. class BulkUpdateAPIView(bulk_mixins.BulkUpdateModelMixin,
  17. GenericAPIView):
  18. def put(self, request, *args, **kwargs):
  19. return self.bulk_update(request, *args, **kwargs)
  20. def patch(self, request, *args, **kwargs):
  21. return self.partial_bulk_update(request, *args, **kwargs)
  22. class BulkDestroyAPIView(bulk_mixins.BulkDestroyModelMixin,
  23. GenericAPIView):
  24. def delete(self, request, *args, **kwargs):
  25. return self.bulk_destroy(request, *args, **kwargs)
  26. class ListBulkCreateAPIView(mixins.ListModelMixin,
  27. bulk_mixins.BulkCreateModelMixin,
  28. GenericAPIView):
  29. def get(self, request, *args, **kwargs):
  30. return self.list(request, *args, **kwargs)
  31. def post(self, request, *args, **kwargs):
  32. return self.create(request, *args, **kwargs)
  33. class ListCreateBulkUpdateAPIView(mixins.ListModelMixin,
  34. mixins.CreateModelMixin,
  35. bulk_mixins.BulkUpdateModelMixin,
  36. GenericAPIView):
  37. def get(self, request, *args, **kwargs):
  38. return self.list(request, *args, **kwargs)
  39. def post(self, request, *args, **kwargs):
  40. return self.create(request, *args, **kwargs)
  41. def put(self, request, *args, **kwargs):
  42. return self.bulk_update(request, *args, **kwargs)
  43. def patch(self, request, *args, **kwargs):
  44. return self.partial_bulk_update(request, *args, **kwargs)
  45. class ListCreateBulkUpdateDestroyAPIView(mixins.ListModelMixin,
  46. mixins.CreateModelMixin,
  47. bulk_mixins.BulkUpdateModelMixin,
  48. bulk_mixins.BulkDestroyModelMixin,
  49. GenericAPIView):
  50. def get(self, request, *args, **kwargs):
  51. return self.list(request, *args, **kwargs)
  52. def post(self, request, *args, **kwargs):
  53. return self.create(request, *args, **kwargs)
  54. def put(self, request, *args, **kwargs):
  55. return self.bulk_update(request, *args, **kwargs)
  56. def patch(self, request, *args, **kwargs):
  57. return self.partial_bulk_update(request, *args, **kwargs)
  58. def delete(self, request, *args, **kwargs):
  59. return self.bulk_destroy(request, *args, **kwargs)
  60. class ListBulkCreateUpdateAPIView(mixins.ListModelMixin,
  61. bulk_mixins.BulkCreateModelMixin,
  62. bulk_mixins.BulkUpdateModelMixin,
  63. GenericAPIView):
  64. def get(self, request, *args, **kwargs):
  65. return self.list(request, *args, **kwargs)
  66. def post(self, request, *args, **kwargs):
  67. return self.create(request, *args, **kwargs)
  68. def put(self, request, *args, **kwargs):
  69. return self.bulk_update(request, *args, **kwargs)
  70. def patch(self, request, *args, **kwargs):
  71. return self.partial_bulk_update(request, *args, **kwargs)
  72. class ListBulkCreateUpdateDestroyAPIView(mixins.ListModelMixin,
  73. bulk_mixins.BulkCreateModelMixin,
  74. bulk_mixins.BulkUpdateModelMixin,
  75. bulk_mixins.BulkDestroyModelMixin,
  76. GenericAPIView):
  77. def get(self, request, *args, **kwargs):
  78. return self.list(request, *args, **kwargs)
  79. def post(self, request, *args, **kwargs):
  80. return self.create(request, *args, **kwargs)
  81. def put(self, request, *args, **kwargs):
  82. return self.bulk_update(request, *args, **kwargs)
  83. def patch(self, request, *args, **kwargs):
  84. return self.partial_bulk_update(request, *args, **kwargs)
  85. def delete(self, request, *args, **kwargs):
  86. return self.bulk_destroy(request, *args, **kwargs)