Commit 5bda1ad6 authored by wanliofficial's avatar wanliofficial

update

parent b574568e
import functools import functools
import json
from flask import request from flask import request
from marshmallow import Schema, ValidationError from marshmallow import Schema, ValidationError
...@@ -10,17 +11,24 @@ def validate_schema(schema_class: Schema): ...@@ -10,17 +11,24 @@ def validate_schema(schema_class: Schema):
def decorator(view_func): def decorator(view_func):
@functools.wraps(view_func) @functools.wraps(view_func)
def inner(*args, **kwargs): def inner(*args, **kwargs):
if request.method == 'GET':
form_data = request.args
else:
if request.json:
form_data = request.json
else:
form_data = request.form
try: try:
if request.method == "GET":
form_data = request.args
elif request.method == "POST":
if request.content_type and request.content_type.startswith('application/json'):
form_data = request.json
elif request.content_type and request.content_type.startswith('application/x-www-form-urlencoded'):
form_data = request.values
elif request.content_type and request.content_type.startswith('multipart/form-data'):
form_data = request.form
else:
form_data = json.loads(request.data)
data = schema_class().load(form_data) data = schema_class().load(form_data)
request.schema_data = data request.schema_data = data
except ValidationError as e: except ValidationError as e:
raise
if config['DEBUG']: if config['DEBUG']:
return response_result(ResponseCode.PARAMETER_ERROR, e.messages if config['DEBUG'] else None) return response_result(ResponseCode.PARAMETER_ERROR, e.messages if config['DEBUG'] else None)
return view_func(*args, **kwargs) return view_func(*args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment