role
This commit is contained in:
parent
29009ef7de
commit
4f06468ec9
@ -10,6 +10,47 @@ import uuid
|
|||||||
|
|
||||||
book_bp = Blueprint('book', __name__)
|
book_bp = Blueprint('book', __name__)
|
||||||
|
|
||||||
|
@book_bp.route('/admin/list')
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def admin_book_list():
|
||||||
|
page = request.args.get('page', 1, type=int)
|
||||||
|
per_page = request.args.get('per_page', 10, type=int)
|
||||||
|
# 只显示状态为1的图书(未下架的图书)
|
||||||
|
query = Book.query.filter_by(status=1)
|
||||||
|
# 搜索功能
|
||||||
|
search = request.args.get('search', '')
|
||||||
|
if search:
|
||||||
|
query = query.filter(
|
||||||
|
(Book.title.contains(search)) |
|
||||||
|
(Book.author.contains(search)) |
|
||||||
|
(Book.isbn.contains(search))
|
||||||
|
)
|
||||||
|
# 分类筛选
|
||||||
|
category_id = request.args.get('category_id', type=int)
|
||||||
|
if category_id:
|
||||||
|
query = query.filter_by(category_id=category_id)
|
||||||
|
# 排序
|
||||||
|
sort = request.args.get('sort', 'id')
|
||||||
|
order = request.args.get('order', 'desc')
|
||||||
|
if order == 'desc':
|
||||||
|
query = query.order_by(getattr(Book, sort).desc())
|
||||||
|
else:
|
||||||
|
query = query.order_by(getattr(Book, sort))
|
||||||
|
pagination = query.paginate(page=page, per_page=per_page)
|
||||||
|
books = pagination.items
|
||||||
|
# 获取所有分类供筛选使用
|
||||||
|
categories = Category.query.all()
|
||||||
|
return render_template('book/list.html',
|
||||||
|
books=books,
|
||||||
|
pagination=pagination,
|
||||||
|
search=search,
|
||||||
|
categories=categories,
|
||||||
|
category_id=category_id,
|
||||||
|
sort=sort,
|
||||||
|
order=order,
|
||||||
|
current_user=g.user,
|
||||||
|
is_admin_view=True) # 指明这是管理视图
|
||||||
|
|
||||||
# 图书列表页面
|
# 图书列表页面
|
||||||
@book_bp.route('/list')
|
@book_bp.route('/list')
|
||||||
|
|||||||
@ -40,8 +40,8 @@
|
|||||||
<li class="{% if '/user/roles' in request.path %}active{% endif %}">
|
<li class="{% if '/user/roles' in request.path %}active{% endif %}">
|
||||||
<a href="{{ url_for('user.role_list') }}"><i class="fas fa-user-tag"></i> 角色管理</a>
|
<a href="{{ url_for('user.role_list') }}"><i class="fas fa-user-tag"></i> 角色管理</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="{% if '/book/list' in request.path %}active{% endif %}">
|
<li class="{% if '/book/admin/list' in request.path %}active{% endif %}">
|
||||||
<a href="{{ url_for('book.book_list') }}"><i class="fas fa-layer-group"></i> 图书管理</a>
|
<a href="{{ url_for('book.admin_book_list') }}"><i class="fas fa-layer-group"></i> 图书管理</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="{% if '/borrow/manage' in request.path %}active{% endif %}">
|
<li class="{% if '/borrow/manage' in request.path %}active{% endif %}">
|
||||||
<a href="#"><i class="fas fa-exchange-alt"></i> 借阅管理</a>
|
<a href="#"><i class="fas fa-exchange-alt"></i> 借阅管理</a>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user