加入webargs验证扩展,分区用于验证的inschema和用户序列化的outschema
This commit is contained in:
@@ -3,7 +3,7 @@ from sqlalchemy import desc
|
||||
from applications.common.utils.http import table_api
|
||||
from applications.common.utils.rights import authorize
|
||||
from applications.models import AdminLog
|
||||
from applications.schemas import LogSchema
|
||||
from applications.schemas import LogOutSchema
|
||||
from applications.common.curd import model_to_dicts
|
||||
|
||||
admin_log = Blueprint('adminLog', __name__, url_prefix='/admin/log')
|
||||
@@ -24,7 +24,7 @@ def login_log():
|
||||
# 使用分页获取data需要.items
|
||||
log = AdminLog.query.filter_by(url='/passport/login').order_by(desc(AdminLog.create_time)).layui_paginate()
|
||||
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(
|
||||
desc(AdminLog.create_time)).layui_paginate()
|
||||
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.extensions import db
|
||||
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')
|
||||
|
||||
@@ -32,7 +32,7 @@ def dict_type_data():
|
||||
# 使用分页获取data需要.items
|
||||
dict_all = DictType.query.filter(mf.get_filter(DictType)).layui_paginate()
|
||||
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)
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ def dict_code_data():
|
||||
type_code = xss_escape(request.args.get('typeCode', type=str))
|
||||
dict_data = DictData.query.filter_by(type_code=type_code).layui_paginate()
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -5,11 +5,8 @@ from datetime import datetime
|
||||
import time
|
||||
import psutil
|
||||
from flask import Blueprint, render_template, jsonify
|
||||
from flask_marshmallow import Marshmallow
|
||||
|
||||
from applications.common.utils.rights import authorize
|
||||
|
||||
ma = Marshmallow()
|
||||
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.validate import xss_escape
|
||||
from applications.extensions import db
|
||||
from applications.models import Power, Role
|
||||
from applications.schemas import PowerSchema2
|
||||
from applications.models import Power
|
||||
from applications.schemas import PowerOutSchema2
|
||||
|
||||
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
||||
|
||||
@@ -22,7 +22,7 @@ def index():
|
||||
def data():
|
||||
power = Power.query.all()
|
||||
res = {
|
||||
"data": curd.model_to_dicts(schema=PowerSchema2, data=power)
|
||||
"data": curd.model_to_dicts(schema=PowerOutSchema2, data=power)
|
||||
}
|
||||
return jsonify(res)
|
||||
|
||||
@@ -37,7 +37,7 @@ def add():
|
||||
@authorize("admin:power:main", log=True)
|
||||
def select_parent():
|
||||
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 = {
|
||||
"status": {"code": 200, "message": "默认"},
|
||||
@@ -118,7 +118,7 @@ def update():
|
||||
def enable():
|
||||
_id = request.json.get('powerId')
|
||||
if id:
|
||||
res = curd.enable_status(Power,_id)
|
||||
res = curd.enable_status(Power, _id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="启用成功")
|
||||
@@ -131,7 +131,7 @@ def enable():
|
||||
def dis_enable():
|
||||
_id = request.json.get('powerId')
|
||||
if id:
|
||||
res = curd.disable_status(Power,_id)
|
||||
res = curd.disable_status(Power, _id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="禁用成功")
|
||||
@@ -144,7 +144,7 @@ def dis_enable():
|
||||
def remove(id):
|
||||
power = Power.query.filter_by(id=id).first()
|
||||
power.role = []
|
||||
|
||||
|
||||
r = Power.query.filter_by(id=id).delete()
|
||||
db.session.commit()
|
||||
if r:
|
||||
|
||||
@@ -7,7 +7,7 @@ from applications.common.utils.rights import authorize
|
||||
from applications.common.utils.validate import xss_escape
|
||||
from applications.extensions import db
|
||||
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')
|
||||
|
||||
@@ -37,7 +37,7 @@ def table():
|
||||
role = Role.query.filter(mf.get_filter(Role)).layui_paginate()
|
||||
count = role.total
|
||||
# 返回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:
|
||||
check_powers_list.append(cp.id)
|
||||
powers = Power.query.all()
|
||||
power_schema = PowerSchema2(many=True) # 用已继承ma.ModelSchema类的自定制类生成序列化类
|
||||
power_schema = PowerOutSchema2(many=True) # 用已继承ma.ModelSchema类的自定制类生成序列化类
|
||||
output = power_schema.dump(powers) # 生成可序列化对象
|
||||
for i in output:
|
||||
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.models import Role
|
||||
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')
|
||||
|
||||
@@ -44,7 +44,7 @@ def data():
|
||||
user = User.query.filter(mf.get_filter(model=User)).layui_paginate()
|
||||
count = user.total
|
||||
# 返回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)
|
||||
|
||||
|
||||
# 用户增加
|
||||
|
||||
Reference in New Issue
Block a user