editor API: activate, edit, propose, accept, etc…
This commit is contained in:
parent
671d138d03
commit
1594e09189
7 changed files with 181 additions and 13 deletions
18
src/c3nav/api/middleware.py
Normal file
18
src/c3nav/api/middleware.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import json
|
||||
|
||||
|
||||
class JsonRequestBodyMiddleware:
|
||||
"""
|
||||
Enables posting JSON requests.
|
||||
"""
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
is_json = request.META.get('CONTENT_TYPE').lower() == 'application/json'
|
||||
if is_json:
|
||||
try:
|
||||
request.json_body = json.loads(request.body)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
return self.get_response(request)
|
|
@ -1,5 +1,3 @@
|
|||
import json
|
||||
|
||||
from rest_framework.exceptions import ParseError
|
||||
|
||||
|
||||
|
@ -7,10 +5,8 @@ def get_api_post_data(request):
|
|||
is_json = request.META.get('CONTENT_TYPE').lower() == 'application/json'
|
||||
if is_json:
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
except json.JSONDecodeError:
|
||||
data = request.json_body
|
||||
except AttributeError:
|
||||
raise ParseError('Invalid JSON.')
|
||||
else:
|
||||
request.json_body = data
|
||||
return data
|
||||
return request.POST
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue