优化curd函数在view的引入方式,优化权限与日志的装饰器
This commit is contained in:
@@ -1,43 +1,40 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
|
||||
from applications.models.admin_dict import DictType, DictData
|
||||
from applications.service.admin.dict import get_dict_type, get_dict_data, save_dict_type, save_dict_data, \
|
||||
delete_type_by_id, delete_data_by_id, update_dict_type, enable_dict_type_status, disable_dict_type_status, \
|
||||
enable_dict_data_status, disable_dict_data_status, update_dict_data
|
||||
from applications.service.admin import dict_curd
|
||||
from applications.service.common.response import table_api, success_api, fail_api
|
||||
from applications.service.route_auth import authorize_and_log
|
||||
from applications.service.route_auth import authorize
|
||||
|
||||
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
||||
|
||||
|
||||
# 数据字典
|
||||
@admin_dict.route('/')
|
||||
@authorize_and_log("admin:dict:main")
|
||||
@authorize("admin:dict:main", log=True)
|
||||
def main():
|
||||
return render_template('admin/dict/main.html')
|
||||
|
||||
|
||||
@admin_dict.route('/dictType/data')
|
||||
@authorize_and_log("admin:dict:main")
|
||||
@authorize("admin:dict:main", log=True)
|
||||
def dictType_data():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
type_name = request.args.get('typeName', type=str)
|
||||
data, count = get_dict_type(page=page, limit=limit, type_name=type_name)
|
||||
data, count = dict_curd.get_dict_type(page=page, limit=limit, type_name=type_name)
|
||||
return table_api(data=data,count=count)
|
||||
|
||||
|
||||
@admin_dict.route('/dictType/add')
|
||||
@authorize_and_log("admin:dict:add")
|
||||
@authorize("admin:dict:add", log=True)
|
||||
def dictType_add():
|
||||
return render_template('admin/dict/add.html')
|
||||
|
||||
|
||||
@admin_dict.route('/dictType/save', methods=['POST'])
|
||||
@authorize_and_log("admin:dict:add")
|
||||
@authorize("admin:dict:add", log=True)
|
||||
def dictType_save():
|
||||
req_json = request.json
|
||||
res = save_dict_type(req_json=req_json)
|
||||
res = dict_curd.save_dict_type(req_json=req_json)
|
||||
if res == None:
|
||||
return fail_api(msg="增加失败")
|
||||
return success_api(msg="增加成功")
|
||||
@@ -45,7 +42,7 @@ def dictType_save():
|
||||
|
||||
# 编辑字典类型
|
||||
@admin_dict.route('/dictType/edit', methods=['GET', 'POST'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictType_edit():
|
||||
id = request.args.get('dictTypeId', type=str)
|
||||
dict_type = DictType.query.filter_by(id=id).first()
|
||||
@@ -54,20 +51,20 @@ def dictType_edit():
|
||||
|
||||
# 编辑字典类型
|
||||
@admin_dict.route('/dictType/update', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictType_update():
|
||||
req_json = request.json
|
||||
update_dict_type(req_json)
|
||||
dict_curd.update_dict_type(req_json)
|
||||
return success_api(msg="更新成功")
|
||||
|
||||
|
||||
# 启用字典
|
||||
@admin_dict.route('/dictType/enable', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictType_enable():
|
||||
id = request.json.get('id')
|
||||
if id:
|
||||
res = enable_dict_type_status(id)
|
||||
res = dict_curd.enable_dict_type_status(id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api("启动成功")
|
||||
@@ -76,11 +73,11 @@ def dictType_enable():
|
||||
|
||||
# 禁用字典
|
||||
@admin_dict.route('/dictType/disable', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictType_disenable():
|
||||
id = request.json.get('id')
|
||||
if id:
|
||||
res = disable_dict_type_status(id)
|
||||
res = dict_curd.disable_dict_type_status(id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api("禁用成功")
|
||||
@@ -89,27 +86,27 @@ def dictType_disenable():
|
||||
|
||||
# 删除字典类型
|
||||
@admin_dict.route('/dictType/remove/<int:id>', methods=['DELETE'])
|
||||
@authorize_and_log("admin:dict:remove")
|
||||
@authorize("admin:dict:remove", log=True)
|
||||
def dictType_delete(id):
|
||||
res = delete_type_by_id(id)
|
||||
res = dict_curd.delete_type_by_id(id)
|
||||
if not res:
|
||||
return fail_api(msg="删除失败")
|
||||
return success_api(msg="删除成功")
|
||||
|
||||
|
||||
@admin_dict.route('/dictData/data')
|
||||
@authorize_and_log("admin:dict:main")
|
||||
@authorize("admin:dict:main", log=True)
|
||||
def dictCode_data():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
type_code = request.args.get('typeCode', type=str)
|
||||
data, count = get_dict_data(page=page, limit=limit, type_code=type_code)
|
||||
data, count = dict_curd.get_dict_data(page=page, limit=limit, type_code=type_code)
|
||||
return table_api(data=data,count=count)
|
||||
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.route('/dictData/add')
|
||||
@authorize_and_log("admin:dict:add")
|
||||
@authorize("admin:dict:add", log=True)
|
||||
def dictData_add():
|
||||
type_code = request.args.get('typeCode', type=str)
|
||||
return render_template('admin/dict/data/add.html', type_code=type_code)
|
||||
@@ -117,7 +114,7 @@ def dictData_add():
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.route('/dictData/save', methods=['POST'])
|
||||
@authorize_and_log("admin:dict:add")
|
||||
@authorize("admin:dict:add", log=True)
|
||||
def dictData_save():
|
||||
req_json = request.json
|
||||
res = save_dict_data(req_json=req_json)
|
||||
@@ -128,7 +125,7 @@ def dictData_save():
|
||||
|
||||
# 编辑字典数据
|
||||
@admin_dict.route('/dictData/edit', methods=['GET', 'POST'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictData_edit():
|
||||
id = request.args.get('dataId', type=str)
|
||||
dict_data = DictData.query.filter_by(id=id).first()
|
||||
@@ -137,7 +134,7 @@ def dictData_edit():
|
||||
|
||||
# 编辑字典数据
|
||||
@admin_dict.route('/dictData/update', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictData_update():
|
||||
req_json = request.json
|
||||
update_dict_data(req_json)
|
||||
@@ -146,7 +143,7 @@ def dictData_update():
|
||||
|
||||
# 启用字典数据
|
||||
@admin_dict.route('/dictData/enable', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictData_enable():
|
||||
id = request.json.get('dataId')
|
||||
if id:
|
||||
@@ -159,7 +156,7 @@ def dictData_enable():
|
||||
|
||||
# 禁用字典数据
|
||||
@admin_dict.route('/dictData/disable', methods=['PUT'])
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
def dictData_disenable():
|
||||
id = request.json.get('dataId')
|
||||
if id:
|
||||
@@ -172,7 +169,7 @@ def dictData_disenable():
|
||||
|
||||
# 删除字典类型
|
||||
@admin_dict.route('dictData/remove/<int:id>', methods=['DELETE'])
|
||||
@authorize_and_log("admin:dict:remove")
|
||||
@authorize("admin:dict:remove", log=True)
|
||||
def dictData_delete(id):
|
||||
res = delete_data_by_id(id)
|
||||
if not res:
|
||||
|
||||
Reference in New Issue
Block a user