From 29a3f740a9253220fd11809be0fea520aa1532b4 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 18 Dec 2017 11:56:04 +1100 Subject: [PATCH] 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 --- micropub/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/micropub/views.py b/micropub/views.py index e20a480..ecb8bce 100644 --- a/micropub/views.py +++ b/micropub/views.py @@ -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):