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
1 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,22 @@ from lemoncurry import utils
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')
class MicropubView(View):
def post(self, request):