This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from WordPress/clean_endpoints
- Loading branch information
Showing
15 changed files
with
379 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.http import JsonResponse | ||
from django.utils.decorators import method_decorator | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.views.generic import View | ||
|
||
|
||
def get_status_code_view(data, status_code=200): | ||
""" | ||
Get a class-based view that returns the given data and status code on all | ||
HTTP methods. Useful for blanket discontinuation of API endpoints. | ||
:param data: the dictionary to serialize as the JSON response | ||
:param status_code: the status code of the returned response | ||
:return: the class based view that returns the same response for all methods | ||
""" | ||
|
||
@method_decorator(csrf_exempt, name='dispatch') | ||
class StatusCodeView(View): | ||
status = status_code | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
return JsonResponse( | ||
status=self.status, | ||
data=data, | ||
) | ||
|
||
return StatusCodeView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.