Coverage for api/utils/status_code_view.py: 91%
11 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
1from django.http import JsonResponse
2from django.utils.decorators import method_decorator
3from django.views.decorators.csrf import csrf_exempt
4from django.views.generic import View
7def get_status_code_view(data, status_code=200):
8 """
9 Get a class-based view that returns the same response on all HTTP methods.
11 This is useful for blanket discontinuation of API endpoints.
13 :param data: the dictionary to serialize as the JSON response
14 :param status_code: the status code of the returned response
15 :return: the class based view that returns the same response for all methods
16 """
18 @method_decorator(csrf_exempt, name="dispatch")
19 class StatusCodeView(View):
20 status = status_code
22 def dispatch(self, request, *args, **kwargs):
23 return JsonResponse(
24 status=self.status,
25 data=data,
26 )
28 return StatusCodeView