|
|
@ -8,6 +8,7 @@ from functools import wraps |
|
|
|
from flask import request |
|
|
|
from flask import request |
|
|
|
from flask import jsonify |
|
|
|
from flask import jsonify |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ForceJSON(object): |
|
|
|
class ForceJSON(object): |
|
|
|
def __init__(self, required=None): |
|
|
|
def __init__(self, required=None): |
|
|
|
self.required = required or [] |
|
|
|
self.required = required or [] |
|
|
@ -18,18 +19,19 @@ class ForceJSON(object): |
|
|
|
json = request.get_json(force=True, silent=True) |
|
|
|
json = request.get_json(force=True, silent=True) |
|
|
|
if not json: |
|
|
|
if not json: |
|
|
|
return jsonify(status='ERROR', |
|
|
|
return jsonify(status='ERROR', |
|
|
|
error='Request MUST be in JSON format'), 400 |
|
|
|
error='Request MUST be in JSON format'), 400 |
|
|
|
|
|
|
|
|
|
|
|
# now we have the JSON, let's check if all the fields are here. |
|
|
|
# now we have the JSON, let's check if all the fields are here. |
|
|
|
missing = [] |
|
|
|
missing = [] |
|
|
|
for field in required or []: |
|
|
|
for field in self.required or []: |
|
|
|
if not field in json: |
|
|
|
if not field in json: |
|
|
|
missing.append(field) |
|
|
|
missing.append(field) |
|
|
|
|
|
|
|
|
|
|
|
if missing: |
|
|
|
if missing: |
|
|
|
|
|
|
|
fields = ', '.join(missing) |
|
|
|
|
|
|
|
error = 'Missing fields: {fields}'.format(fields=fields) |
|
|
|
return jsonify(status='ERROR', |
|
|
|
return jsonify(status='ERROR', |
|
|
|
error='Missing fields: {fields}'.format( |
|
|
|
error=error) |
|
|
|
fields=', '.join(missing))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return func(*args, **kwargs) |
|
|
|
return func(*args, **kwargs) |
|
|
|
return check_json |
|
|
|
return check_json |
|
|
|