editor API: activate, edit, propose, accept, etc…

This commit is contained in:
Laura Klünder 2018-11-29 01:30:53 +01:00
parent 671d138d03
commit 1594e09189
7 changed files with 181 additions and 13 deletions

View 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)

View file

@ -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