更新 views.py
parent
f1fac2037a
commit
df2c025c63
16
app/views.py
16
app/views.py
|
|
@ -1,4 +1,4 @@
|
|||
from flask import Flask, redirect, url_for, render_template, session, jsonify,request
|
||||
from flask import Flask, redirect, url_for, render_template, session, jsonify,request,send_file
|
||||
from db.connection import MySQLPool
|
||||
from config import SECRET_KEY
|
||||
from db.database_manager import DatabaseManager
|
||||
|
|
@ -7,14 +7,15 @@ from models.Teacher import Teacher
|
|||
from models.User import User
|
||||
import logging
|
||||
from config import LOGGING_CONFIG
|
||||
|
||||
from config import FILE_PATH
|
||||
app = Flask(__name__, static_folder='static')
|
||||
app.secret_key = SECRET_KEY # 从配置文件设置
|
||||
logging.basicConfig(**LOGGING_CONFIG)
|
||||
|
||||
# 一个全局MySQLPool对象,用于管理数据库连接
|
||||
mysql_pool = MySQLPool()
|
||||
|
||||
# 配置文件路径,例如指向一个 'files' 目录
|
||||
app.config['FILE_PATH'] = FILE_PATH
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
|
|
@ -224,7 +225,6 @@ def teacher_attendance():
|
|||
@app.route('/api/get-teacher-attendance-table', methods=['GET'])
|
||||
def get_current_teacher_courses():
|
||||
number = session.get('number')
|
||||
logging.info(number)
|
||||
# 获取分页参数
|
||||
page = request.args.get('page', 1, type=int) # 如果没有提供,默认为第一页
|
||||
limit = request.args.get('limit', 10, type=int) # 如果没有提供,默认每页10条
|
||||
|
|
@ -232,7 +232,7 @@ def get_current_teacher_courses():
|
|||
# 获取所有课程数据
|
||||
db_manager = DatabaseManager()
|
||||
all_course_data = db_manager.get_current_teacher_courses(number)
|
||||
|
||||
logging.info(f"all_course_data: {all_course_data}")
|
||||
# 计算分页的起始和结束索引
|
||||
start = (page - 1) * limit
|
||||
end = start + limit
|
||||
|
|
@ -250,6 +250,12 @@ def get_current_teacher_courses():
|
|||
# 将查询结果转换为JSON格式并返回
|
||||
return jsonify(response)
|
||||
|
||||
@app.route('/files/<filename>')
|
||||
def download_template():
|
||||
print(FILE_PATH)
|
||||
# 确保这个路径是你的文件实际所在的服务器路径
|
||||
path = "./files/template.xlsx"
|
||||
return send_file(path, as_attachment=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
|
|
|||
Reference in New Issue