加入webargs验证扩展,分区用于验证的inschema和用户序列化的outschema
This commit is contained in:
@@ -5,7 +5,7 @@ from flask import session, make_response, current_app
|
|||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
|
||||||
from applications.common.utils.gen_captcha import gen_captcha
|
from applications.common.utils.gen_captcha import gen_captcha
|
||||||
from applications.schemas import PowerSchema
|
from applications.schemas import PowerOutSchema
|
||||||
|
|
||||||
|
|
||||||
# 授权路由存入session
|
# 授权路由存入session
|
||||||
@@ -39,7 +39,7 @@ def make_menu_tree():
|
|||||||
if int(p.type) == 0 or int(p.type) == 1:
|
if int(p.type) == 0 or int(p.type) == 1:
|
||||||
powers.append(p)
|
powers.append(p)
|
||||||
|
|
||||||
power_schema = PowerSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
power_schema = PowerOutSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
||||||
power_dict = power_schema.dump(powers) # 生成可序列化对象
|
power_dict = power_schema.dump(powers) # 生成可序列化对象
|
||||||
power_dict.sort(key=lambda x: x['id'], reverse=True)
|
power_dict.sort(key=lambda x: x['id'], reverse=True)
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ from sqlalchemy import desc
|
|||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.extensions.init_upload import photos
|
from applications.extensions.init_upload import photos
|
||||||
from applications.models import Photo
|
from applications.models import Photo
|
||||||
from applications.schemas import PhotoSchema
|
from applications.schemas import PhotoOutSchema
|
||||||
from applications.common.curd import model_to_dicts
|
from applications.common.curd import model_to_dicts
|
||||||
|
|
||||||
|
|
||||||
def get_photo(page, limit):
|
def get_photo(page, limit):
|
||||||
photo = Photo.query.order_by(desc(Photo.create_time)).paginate(page=page, per_page=limit, error_out=False)
|
photo = Photo.query.order_by(desc(Photo.create_time)).paginate(page=page, per_page=limit, error_out=False)
|
||||||
count = Photo.query.count()
|
count = Photo.query.count()
|
||||||
data = model_to_dicts(schema=PhotoSchema, data=photo.items)
|
data = model_to_dicts(schema=PhotoOutSchema, data=photo.items)
|
||||||
return data, count
|
return data, count
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import render_template
|
from flask import render_template, jsonify
|
||||||
|
|
||||||
|
|
||||||
def init_error_views(app):
|
def init_error_views(app):
|
||||||
@@ -13,3 +13,22 @@ def init_error_views(app):
|
|||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
def internal_server_error(e):
|
def internal_server_error(e):
|
||||||
return render_template('errors/500.html'), 500
|
return render_template('errors/500.html'), 500
|
||||||
|
|
||||||
|
# Return validation errors as JSON
|
||||||
|
@app.errorhandler(422)
|
||||||
|
@app.errorhandler(400)
|
||||||
|
def handle_error(err):
|
||||||
|
headers = err.data.get("headers", None)
|
||||||
|
messages = err.data.get("messages", ["Invalid request."]).get('json')
|
||||||
|
print(err.data.get("messages"))
|
||||||
|
print(messages.items())
|
||||||
|
msg = ''
|
||||||
|
|
||||||
|
for i in messages.items():
|
||||||
|
msg = str(i[0]) + str(i[1][0])
|
||||||
|
break
|
||||||
|
|
||||||
|
if headers:
|
||||||
|
return jsonify({"success": False, "msg": msg})
|
||||||
|
else:
|
||||||
|
return jsonify({"success": False, "msg": msg})
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from marshmallow import EXCLUDE
|
||||||
|
from webargs.flaskparser import FlaskParser
|
||||||
|
|
||||||
|
|
||||||
|
class Parser(FlaskParser):
|
||||||
|
DEFAULT_UNKNOWN_BY_LOCATION = {"query": EXCLUDE}
|
||||||
|
|
||||||
|
|
||||||
|
parser = Parser()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from .admin_user import UserSchema
|
from .admin_user import UserOutSchema
|
||||||
from .admin_role import RoleSchema
|
from .admin_role import RoleOutSchema
|
||||||
from .admin_power import PowerSchema, PowerSchema2
|
from .admin_power import PowerOutSchema, PowerOutSchema2
|
||||||
from .admin_dict import DictDataSchema, DictTypeSchema
|
from .admin_dict import DictDataOutSchema, DictTypeOutSchema
|
||||||
from .admin_dept import DeptSchema
|
from .admin_dept import DeptOutSchema
|
||||||
from .admin_log import LogSchema
|
from .admin_log import LogOutSchema
|
||||||
from .admin_photo import PhotoSchema
|
from .admin_photo import PhotoOutSchema
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
from applications.extensions import ma
|
from applications.extensions import ma
|
||||||
from marshmallow import fields, validate
|
from marshmallow import fields, validate
|
||||||
|
|
||||||
|
|
||||||
class DeptSchema(ma.Schema):
|
class DeptInSchema(ma.Schema):
|
||||||
|
parentId = fields.Integer(required=True)
|
||||||
|
deptName = fields.Str(required=True)
|
||||||
|
leader = fields.Str(required=True)
|
||||||
|
phone = fields.Str(required=True)
|
||||||
|
email = fields.Str(validate=validate.Email())
|
||||||
|
address = fields.Str()
|
||||||
|
status = fields.Str(validate=validate.OneOf(["0", "1"]))
|
||||||
|
sort = fields.Integer()
|
||||||
|
|
||||||
|
|
||||||
|
class DeptOutSchema(ma.Schema):
|
||||||
deptId = fields.Integer(attribute="id")
|
deptId = fields.Integer(attribute="id")
|
||||||
parentId = fields.Integer(attribute="parent_id")
|
parentId = fields.Integer(attribute="parent_id")
|
||||||
deptName = fields.Str(attribute="dept_name")
|
deptName = fields.Str(attribute="dept_name")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from applications.extensions import ma
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|
||||||
class DictTypeSchema(ma.Schema):
|
class DictTypeOutSchema(ma.Schema):
|
||||||
id = fields.Str(attribute="id")
|
id = fields.Str(attribute="id")
|
||||||
typeName = fields.Str(attribute="type_name")
|
typeName = fields.Str(attribute="type_name")
|
||||||
typeCode = fields.Str(attribute="type_code")
|
typeCode = fields.Str(attribute="type_code")
|
||||||
@@ -13,7 +13,7 @@ class DictTypeSchema(ma.Schema):
|
|||||||
enable = fields.Str()
|
enable = fields.Str()
|
||||||
|
|
||||||
|
|
||||||
class DictDataSchema(ma.Schema):
|
class DictDataOutSchema(ma.Schema):
|
||||||
dataId = fields.Str(attribute="id")
|
dataId = fields.Str(attribute="id")
|
||||||
dataLabel = fields.Str(attribute="data_label")
|
dataLabel = fields.Str(attribute="data_label")
|
||||||
dataValue = fields.Str(attribute="data_value")
|
dataValue = fields.Str(attribute="data_value")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from applications.extensions import ma
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|
||||||
class LogSchema(ma.Schema):
|
class LogOutSchema(ma.Schema):
|
||||||
id = fields.Integer()
|
id = fields.Integer()
|
||||||
method = fields.Str()
|
method = fields.Str()
|
||||||
uid = fields.Str()
|
uid = fields.Str()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from applications.extensions import ma
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|
||||||
class PhotoSchema(ma.Schema):
|
class PhotoOutSchema(ma.Schema):
|
||||||
id = fields.Integer()
|
id = fields.Integer()
|
||||||
name = fields.Str()
|
name = fields.Str()
|
||||||
href = fields.Str()
|
href = fields.Str()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from marshmallow import fields
|
|||||||
|
|
||||||
|
|
||||||
# 权限models序列化类
|
# 权限models序列化类
|
||||||
class PowerSchema(ma.Schema):
|
class PowerOutSchema(ma.Schema):
|
||||||
id = fields.Integer()
|
id = fields.Integer()
|
||||||
title = fields.Str(attribute="name")
|
title = fields.Str(attribute="name")
|
||||||
type = fields.Str()
|
type = fields.Str()
|
||||||
@@ -18,7 +18,7 @@ class PowerSchema(ma.Schema):
|
|||||||
enable = fields.Integer()
|
enable = fields.Integer()
|
||||||
|
|
||||||
|
|
||||||
class PowerSchema2(ma.Schema): # 序列化类
|
class PowerOutSchema2(ma.Schema): # 序列化类
|
||||||
powerId = fields.Str(attribute="id")
|
powerId = fields.Str(attribute="id")
|
||||||
powerName = fields.Str(attribute="name")
|
powerName = fields.Str(attribute="name")
|
||||||
powerType = fields.Str(attribute="type")
|
powerType = fields.Str(attribute="type")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from applications.extensions import ma
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|
||||||
class RoleSchema(ma.Schema):
|
class RoleOutSchema(ma.Schema):
|
||||||
id = fields.Integer()
|
id = fields.Integer()
|
||||||
roleName = fields.Str(attribute="name")
|
roleName = fields.Str(attribute="name")
|
||||||
roleCode = fields.Str(attribute="code")
|
roleCode = fields.Str(attribute="code")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from applications.models import Dept
|
|||||||
|
|
||||||
|
|
||||||
# 用户models的序列化类
|
# 用户models的序列化类
|
||||||
class UserSchema(ma.Schema):
|
class UserOutSchema(ma.Schema):
|
||||||
id = fields.Integer()
|
id = fields.Integer()
|
||||||
username = fields.Str()
|
username = fields.Str()
|
||||||
realname = fields.Str()
|
realname = fields.Str()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from sqlalchemy import desc
|
|||||||
from applications.common.utils.http import table_api
|
from applications.common.utils.http import table_api
|
||||||
from applications.common.utils.rights import authorize
|
from applications.common.utils.rights import authorize
|
||||||
from applications.models import AdminLog
|
from applications.models import AdminLog
|
||||||
from applications.schemas import LogSchema
|
from applications.schemas import LogOutSchema
|
||||||
from applications.common.curd import model_to_dicts
|
from applications.common.curd import model_to_dicts
|
||||||
|
|
||||||
admin_log = Blueprint('adminLog', __name__, url_prefix='/admin/log')
|
admin_log = Blueprint('adminLog', __name__, url_prefix='/admin/log')
|
||||||
@@ -24,7 +24,7 @@ def login_log():
|
|||||||
# 使用分页获取data需要.items
|
# 使用分页获取data需要.items
|
||||||
log = AdminLog.query.filter_by(url='/passport/login').order_by(desc(AdminLog.create_time)).layui_paginate()
|
log = AdminLog.query.filter_by(url='/passport/login').order_by(desc(AdminLog.create_time)).layui_paginate()
|
||||||
count = log.total
|
count = log.total
|
||||||
return table_api(data= model_to_dicts(schema=LogSchema, data=log.items), count=count)
|
return table_api(data= model_to_dicts(schema=LogOutSchema, data=log.items), count=count)
|
||||||
|
|
||||||
|
|
||||||
# 操作日志
|
# 操作日志
|
||||||
@@ -37,4 +37,4 @@ def operate_log():
|
|||||||
AdminLog.url != '/passport/login').order_by(
|
AdminLog.url != '/passport/login').order_by(
|
||||||
desc(AdminLog.create_time)).layui_paginate()
|
desc(AdminLog.create_time)).layui_paginate()
|
||||||
count = log.total
|
count = log.total
|
||||||
return table_api(data=model_to_dicts(schema=LogSchema, data=log.items), count=count)
|
return table_api(data=model_to_dicts(schema=LogOutSchema, data=log.items), count=count)
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
from flask import Blueprint
|
|
||||||
|
|
||||||
admin_curd = Blueprint('adminCurd', __name__, url_prefix='/admin/curd')
|
|
||||||
|
|
||||||
|
|
||||||
@admin_curd.route('/')
|
|
||||||
def index():
|
|
||||||
return "功能开发中"
|
|
||||||
@@ -7,7 +7,7 @@ from applications.common.utils.rights import authorize
|
|||||||
from applications.common.utils.validate import xss_escape
|
from applications.common.utils.validate import xss_escape
|
||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import DictType, DictData
|
from applications.models import DictType, DictData
|
||||||
from applications.schemas import DictTypeSchema, DictDataSchema
|
from applications.schemas import DictTypeOutSchema, DictDataOutSchema
|
||||||
|
|
||||||
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ def dict_type_data():
|
|||||||
# 使用分页获取data需要.items
|
# 使用分页获取data需要.items
|
||||||
dict_all = DictType.query.filter(mf.get_filter(DictType)).layui_paginate()
|
dict_all = DictType.query.filter(mf.get_filter(DictType)).layui_paginate()
|
||||||
count = dict_all.total
|
count = dict_all.total
|
||||||
data = curd.model_to_dicts(schema=DictTypeSchema, data=dict_all.items)
|
data = curd.model_to_dicts(schema=DictTypeOutSchema, data=dict_all.items)
|
||||||
return table_api(data=data, count=count)
|
return table_api(data=data, count=count)
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ def dict_code_data():
|
|||||||
type_code = xss_escape(request.args.get('typeCode', type=str))
|
type_code = xss_escape(request.args.get('typeCode', type=str))
|
||||||
dict_data = DictData.query.filter_by(type_code=type_code).layui_paginate()
|
dict_data = DictData.query.filter_by(type_code=type_code).layui_paginate()
|
||||||
count = dict_data.total
|
count = dict_data.total
|
||||||
data = curd.model_to_dicts(schema=DictDataSchema, data=dict_data.items)
|
data = curd.model_to_dicts(schema=DictDataOutSchema, data=dict_data.items)
|
||||||
return table_api(data=data, count=count)
|
return table_api(data=data, count=count)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ from datetime import datetime
|
|||||||
import time
|
import time
|
||||||
import psutil
|
import psutil
|
||||||
from flask import Blueprint, render_template, jsonify
|
from flask import Blueprint, render_template, jsonify
|
||||||
from flask_marshmallow import Marshmallow
|
|
||||||
|
|
||||||
from applications.common.utils.rights import authorize
|
from applications.common.utils.rights import authorize
|
||||||
|
|
||||||
ma = Marshmallow()
|
|
||||||
admin_monitor_bp = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
admin_monitor_bp = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ from applications.common.utils.http import success_api, fail_api
|
|||||||
from applications.common.utils.rights import authorize
|
from applications.common.utils.rights import authorize
|
||||||
from applications.common.utils.validate import xss_escape
|
from applications.common.utils.validate import xss_escape
|
||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import Power, Role
|
from applications.models import Power
|
||||||
from applications.schemas import PowerSchema2
|
from applications.schemas import PowerOutSchema2
|
||||||
|
|
||||||
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ def index():
|
|||||||
def data():
|
def data():
|
||||||
power = Power.query.all()
|
power = Power.query.all()
|
||||||
res = {
|
res = {
|
||||||
"data": curd.model_to_dicts(schema=PowerSchema2, data=power)
|
"data": curd.model_to_dicts(schema=PowerOutSchema2, data=power)
|
||||||
}
|
}
|
||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ def add():
|
|||||||
@authorize("admin:power:main", log=True)
|
@authorize("admin:power:main", log=True)
|
||||||
def select_parent():
|
def select_parent():
|
||||||
power = Power.query.all()
|
power = Power.query.all()
|
||||||
res = curd.model_to_dicts(schema=PowerSchema2, data=power)
|
res = curd.model_to_dicts(schema=PowerOutSchema2, data=power)
|
||||||
res.append({"powerId": 0, "powerName": "顶级权限", "parentId": -1})
|
res.append({"powerId": 0, "powerName": "顶级权限", "parentId": -1})
|
||||||
res = {
|
res = {
|
||||||
"status": {"code": 200, "message": "默认"},
|
"status": {"code": 200, "message": "默认"},
|
||||||
@@ -118,7 +118,7 @@ def update():
|
|||||||
def enable():
|
def enable():
|
||||||
_id = request.json.get('powerId')
|
_id = request.json.get('powerId')
|
||||||
if id:
|
if id:
|
||||||
res = curd.enable_status(Power,_id)
|
res = curd.enable_status(Power, _id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="启用成功")
|
return success_api(msg="启用成功")
|
||||||
@@ -131,7 +131,7 @@ def enable():
|
|||||||
def dis_enable():
|
def dis_enable():
|
||||||
_id = request.json.get('powerId')
|
_id = request.json.get('powerId')
|
||||||
if id:
|
if id:
|
||||||
res = curd.disable_status(Power,_id)
|
res = curd.disable_status(Power, _id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="禁用成功")
|
return success_api(msg="禁用成功")
|
||||||
@@ -144,7 +144,7 @@ def dis_enable():
|
|||||||
def remove(id):
|
def remove(id):
|
||||||
power = Power.query.filter_by(id=id).first()
|
power = Power.query.filter_by(id=id).first()
|
||||||
power.role = []
|
power.role = []
|
||||||
|
|
||||||
r = Power.query.filter_by(id=id).delete()
|
r = Power.query.filter_by(id=id).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if r:
|
if r:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from applications.common.utils.rights import authorize
|
|||||||
from applications.common.utils.validate import xss_escape
|
from applications.common.utils.validate import xss_escape
|
||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import Role, Power, User
|
from applications.models import Role, Power, User
|
||||||
from applications.schemas import RoleSchema, PowerSchema2
|
from applications.schemas import RoleOutSchema, PowerOutSchema2
|
||||||
|
|
||||||
admin_role = Blueprint('adminRole', __name__, url_prefix='/admin/role')
|
admin_role = Blueprint('adminRole', __name__, url_prefix='/admin/role')
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ def table():
|
|||||||
role = Role.query.filter(mf.get_filter(Role)).layui_paginate()
|
role = Role.query.filter(mf.get_filter(Role)).layui_paginate()
|
||||||
count = role.total
|
count = role.total
|
||||||
# 返回api
|
# 返回api
|
||||||
return table_api(data=model_to_dicts(schema=RoleSchema, data=role.items), count=count)
|
return table_api(data=model_to_dicts(schema=RoleOutSchema, data=role.items), count=count)
|
||||||
|
|
||||||
|
|
||||||
# 角色增加
|
# 角色增加
|
||||||
@@ -86,7 +86,7 @@ def get_role_power(id):
|
|||||||
for cp in check_powers:
|
for cp in check_powers:
|
||||||
check_powers_list.append(cp.id)
|
check_powers_list.append(cp.id)
|
||||||
powers = Power.query.all()
|
powers = Power.query.all()
|
||||||
power_schema = PowerSchema2(many=True) # 用已继承ma.ModelSchema类的自定制类生成序列化类
|
power_schema = PowerOutSchema2(many=True) # 用已继承ma.ModelSchema类的自定制类生成序列化类
|
||||||
output = power_schema.dump(powers) # 生成可序列化对象
|
output = power_schema.dump(powers) # 生成可序列化对象
|
||||||
for i in output:
|
for i in output:
|
||||||
if int(i.get("powerId")) in check_powers_list:
|
if int(i.get("powerId")) in check_powers_list:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from applications.common.utils.validate import xss_escape
|
|||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import Role
|
from applications.models import Role
|
||||||
from applications.models import User, AdminLog
|
from applications.models import User, AdminLog
|
||||||
from applications.schemas import UserSchema
|
from applications.schemas import UserOutSchema
|
||||||
|
|
||||||
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ def data():
|
|||||||
user = User.query.filter(mf.get_filter(model=User)).layui_paginate()
|
user = User.query.filter(mf.get_filter(model=User)).layui_paginate()
|
||||||
count = user.total
|
count = user.total
|
||||||
# 返回api
|
# 返回api
|
||||||
return table_api(data=model_to_dicts(schema=UserSchema, data=user.items), count=count)
|
return table_api(data=model_to_dicts(schema=UserOutSchema, data=user.items), count=count)
|
||||||
|
|
||||||
|
|
||||||
# 用户增加
|
# 用户增加
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request, jsonify
|
||||||
from marshmallow import INCLUDE
|
from marshmallow import INCLUDE
|
||||||
|
from webargs.flaskparser import use_args
|
||||||
|
|
||||||
from applications.common import curd
|
from applications.common import curd
|
||||||
from applications.common.utils.http import success_api, fail_api
|
from applications.common.utils.http import success_api, fail_api
|
||||||
@@ -7,7 +8,8 @@ from applications.common.utils.rights import authorize
|
|||||||
from applications.common.utils import validate
|
from applications.common.utils import validate
|
||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import Dept, User
|
from applications.models import Dept, User
|
||||||
from applications.schemas import DeptSchema
|
from applications.schemas import DeptOutSchema
|
||||||
|
from applications.schemas.admin_dept import DeptInSchema
|
||||||
|
|
||||||
dept_bp = Blueprint('dept', __name__, url_prefix='/dept')
|
dept_bp = Blueprint('dept', __name__, url_prefix='/dept')
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ def main():
|
|||||||
@authorize("admin:dept:main", log=True)
|
@authorize("admin:dept:main", log=True)
|
||||||
def data():
|
def data():
|
||||||
dept = Dept.query.order_by(Dept.sort).all()
|
dept = Dept.query.order_by(Dept.sort).all()
|
||||||
power_data = curd.model_to_dicts(schema=DeptSchema, data=dept)
|
power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept)
|
||||||
res = {
|
res = {
|
||||||
"data": power_data
|
"data": power_data
|
||||||
}
|
}
|
||||||
@@ -43,7 +45,7 @@ def add():
|
|||||||
@authorize("admin:dept:main", log=True)
|
@authorize("admin:dept:main", log=True)
|
||||||
def tree():
|
def tree():
|
||||||
dept = Dept.query.order_by(Dept.sort).all()
|
dept = Dept.query.order_by(Dept.sort).all()
|
||||||
power_data = curd.model_to_dicts(schema=DeptSchema, data=dept)
|
power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept)
|
||||||
res = {
|
res = {
|
||||||
"status": {"code": 200, "message": "默认"},
|
"status": {"code": 200, "message": "默认"},
|
||||||
"data": power_data
|
"data": power_data
|
||||||
@@ -54,26 +56,17 @@ def tree():
|
|||||||
|
|
||||||
@dept_bp.post('/save')
|
@dept_bp.post('/save')
|
||||||
@authorize("admin:dept:add", log=True)
|
@authorize("admin:dept:add", log=True)
|
||||||
def save():
|
@use_args(DeptInSchema(), location="json", unknown=True)
|
||||||
req = request.json
|
def save(args):
|
||||||
validate.check_data(DeptSchema(unknown=INCLUDE), req)
|
|
||||||
address = validate.xss_escape(req.get("address"))
|
|
||||||
deptName = validate.xss_escape(req.get("deptName"))
|
|
||||||
email = validate.xss_escape(req.get("email"))
|
|
||||||
leader = validate.xss_escape(req.get("leader"))
|
|
||||||
parentId = validate.xss_escape(req.get("parentId"))
|
|
||||||
phone = validate.xss_escape(req.get("phone"))
|
|
||||||
sort = validate.xss_escape(req.get("sort"))
|
|
||||||
status = validate.xss_escape(req.get("status"))
|
|
||||||
dept = Dept(
|
dept = Dept(
|
||||||
parent_id=parentId,
|
parent_id=args['parentId'],
|
||||||
dept_name=deptName,
|
dept_name=args['deptName'],
|
||||||
sort=sort,
|
sort=args['sort'],
|
||||||
leader=leader,
|
leader=args['leader'],
|
||||||
phone=phone,
|
phone=args['phone'],
|
||||||
email=email,
|
email=args['email'],
|
||||||
status=status,
|
status=args['status'],
|
||||||
address=address
|
address=args['address']
|
||||||
)
|
)
|
||||||
r = db.session.add(dept)
|
r = db.session.add(dept)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ Flask-Mail==0.9.1
|
|||||||
sqlparse==0.4.2
|
sqlparse==0.4.2
|
||||||
captcha==0.3
|
captcha==0.3
|
||||||
Pillow==8.2.0
|
Pillow==8.2.0
|
||||||
python-dotenv==0.19.1
|
python-dotenv==0.19.1
|
||||||
|
webargs==8.0.1
|
||||||
Reference in New Issue
Block a user