Add a function to convert form-encoded micropub requests into JSON micropub requests - I'll be changing the actual endpoint to accept JSON and use this to keep accepting form-encoded as well

This commit is contained in:
Danielle McLean 2017-12-18 11:56:04 +11:00
parent 14723b03ff
commit 29a3f740a9
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5

View file

@ -12,6 +12,22 @@ from lemoncurry import utils
from lemonauth import tokens from lemonauth import tokens
def form_to_mf2(post):
properties = {}
for key in post.keys():
if key.endswith('[]'):
key = key[:-2]
if key == 'access_token':
continue
properties[key] = post.getlist(key) + post.getlist(key + '[]')
type = []
if 'h' in properties:
type = ['h-' + p for p in properties['h']]
del properties['h']
return {'type': type, 'properties': properties}
@method_decorator(csrf_exempt, name='dispatch') @method_decorator(csrf_exempt, name='dispatch')
class MicropubView(View): class MicropubView(View):
def post(self, request): def post(self, request):