2018-07-02 01:08:13 -04:00
|
|
|
import json
|
|
|
|
|
2018-01-28 18:28:46 -05:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
|
|
|
|
from lemonauth import tokens
|
|
|
|
|
|
|
|
from .create import create
|
2018-07-02 01:08:13 -04:00
|
|
|
from .delete import delete
|
2018-01-28 18:28:46 -05:00
|
|
|
from .query import query
|
|
|
|
|
2018-07-02 01:08:13 -04:00
|
|
|
actions = {
|
|
|
|
'create': create,
|
|
|
|
'delete': delete,
|
|
|
|
}
|
|
|
|
|
2018-01-28 18:28:46 -05:00
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@require_http_methods(['GET', 'HEAD', 'POST'])
|
|
|
|
def micropub(request):
|
2018-07-02 19:51:51 -04:00
|
|
|
request.token = tokens.auth(request)
|
2018-01-28 18:28:46 -05:00
|
|
|
if request.method in ('GET', 'HEAD'):
|
|
|
|
return query(request)
|
2018-07-02 01:08:13 -04:00
|
|
|
|
|
|
|
action = request.POST.get('action', 'create')
|
|
|
|
if request.content_type == 'application/json':
|
|
|
|
request.json = json.load(request)
|
|
|
|
action = request.json.get('action', 'create')
|
2018-07-02 20:03:35 -04:00
|
|
|
if action not in actions:
|
|
|
|
raise error.bad_req('unknown action: {}'.format(action))
|
|
|
|
return actions[action](request)
|