Package coprs :: Package views :: Package apiv3_ns :: Module json2form
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.apiv3_ns.json2form

 1  import flask 
 2  from werkzeug.datastructures import MultiDict 
 3   
 4   
5 -def get_form_compatible_data():
6 input = without_empty_fields(get_input_dict()) 7 output = {} 8 9 for k, v in input.items(): 10 # Transform lists to strings separated with spaces 11 if type(v) == list: 12 v = " ".join(map(str, v)) 13 14 output[k] = v 15 16 # Our WTForms expect chroots to be this way 17 for chroot in input.get("chroots") or []: 18 output[chroot] = True 19 20 output.update(flask.request.files or {}) 21 return MultiDict(output)
22 23
24 -def get_input_dict():
25 return flask.request.json or flask.request.form
26 27
28 -def get_input():
29 return MultiDict(get_input_dict())
30 31
32 -def without_empty_fields(input):
33 output = input.copy() 34 for k, v in input.items(): 35 # Field with None value is like if it wasn't send with forms 36 if v is None: 37 del output[k] 38 return output
39