优化curd函数在view的引入方式,优化权限与日志的装饰器
This commit is contained in:
@@ -2,38 +2,37 @@ import os
|
||||
from flask import Blueprint, request, render_template, jsonify, current_app
|
||||
from applications.models import db
|
||||
from applications.models.admin_photo import Photo
|
||||
from applications.service.admin.file import get_photo, upload_one, delete_photo_by_id
|
||||
from applications.service.admin import file_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_file = Blueprint('adminFile', __name__, url_prefix='/admin/file')
|
||||
|
||||
|
||||
# 图片管理
|
||||
@admin_file.route('/')
|
||||
@authorize_and_log("admin:file:main")
|
||||
@authorize("admin:file:main", log=True)
|
||||
def index():
|
||||
return render_template('admin/photo/photo.html')
|
||||
|
||||
|
||||
# 图片数据
|
||||
@admin_file.route('/table')
|
||||
@authorize_and_log("admin:file:main")
|
||||
@authorize("admin:file:main", log=True)
|
||||
def table():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
data, count = get_photo(page=page, limit=limit)
|
||||
data, count = file_curd.get_photo(page=page, limit=limit)
|
||||
return table_api(data=data, count=count)
|
||||
|
||||
|
||||
# 上传接口
|
||||
@admin_file.route('/upload', methods=['GET', 'POST'])
|
||||
@authorize_and_log("admin:file:add")
|
||||
@authorize("admin:file:add", log=True)
|
||||
def upload():
|
||||
if request.method == 'POST' and 'file' in request.files:
|
||||
photo = request.files['file']
|
||||
mime = request.files['file'].content_type
|
||||
file_url = upload_one(photo=photo, mime=mime)
|
||||
file_url = file_curd.upload_one(photo=photo, mime=mime)
|
||||
res = {
|
||||
"msg": "上传成功",
|
||||
"code": 0,
|
||||
@@ -48,10 +47,10 @@ def upload():
|
||||
|
||||
# 图片删除
|
||||
@admin_file.route('/delete', methods=['GET', 'POST'])
|
||||
@authorize_and_log("admin:file:delete")
|
||||
@authorize("admin:file:delete", log=True)
|
||||
def delete():
|
||||
id = request.form.get('id')
|
||||
res = delete_photo_by_id(id)
|
||||
res = file_curd.delete_photo_by_id(id)
|
||||
if res:
|
||||
return success_api(msg="删除成功")
|
||||
else:
|
||||
@@ -60,7 +59,7 @@ def delete():
|
||||
|
||||
# 图片批量删除
|
||||
@admin_file.route('/batchRemove', methods=['GET', 'POST'])
|
||||
@authorize_and_log("admin:file:delete")
|
||||
@authorize("admin:file:delete", log=True)
|
||||
def batchRemove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
photo_name = Photo.query.filter(Photo.id.in_(ids)).all()
|
||||
|
||||
Reference in New Issue
Block a user