generics.py 4.4 KB

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