def add_build(): data = request.get_json() validate = { "filename": "str", "device": "str", "version": "str", "md5sum": "str", "url": "str", "romtype": "str", "romsize": "int" } #bad data sent if not data: return jsonify(validate), 400 #validate keys all exist for key in validate.keys(): if key not in data: return jsonify(validate), 406 # validate types for key in validate.keys(): try: locate(validate[key])(data[key]) except: return jsonify({ "error": "{} must be parseable by python's {} class".format( key, validate[key]) }), 406 rom = Rom(**data) rom.save() return "ok", 200
def addrom(filename, device, version, datetime, romtype, md5sum, url): Rom(filename=filename, datetime=datetime, device=device, version=version, romtype=romtype, md5sum=md5sum, url=url).save()