diff --git a/check_applications.py b/check_applications.py new file mode 100644 index 0000000..c786140 --- /dev/null +++ b/check_applications.py @@ -0,0 +1,50 @@ +""" +检查教师申请数据的完整性 +""" +import sqlite3 + +db_path = 'instance/database.db' +conn = sqlite3.connect(db_path) +cursor = conn.cursor() + +print("检查教师申请数据完整性...\n") + +# 获取所有待审批的申请 +cursor.execute(""" + SELECT id, user_id, contest_id, name, email, status + FROM teacher_application + WHERE status = 'pending' +""") +apps = cursor.fetchall() + +if not apps: + print("没有待审批的教师申请") +else: + print(f"找到 {len(apps)} 个待审批的申请\n") + + for app in apps: + app_id, user_id, contest_id, name, email, status = app + print(f"申请 ID: {app_id}") + print(f" 用户ID: {user_id}, 杯赛ID: {contest_id}") + print(f" 姓名: {name}, 邮箱: {email}") + + # 检查用户是否存在 + cursor.execute("SELECT id, name FROM user WHERE id = ?", (user_id,)) + user = cursor.fetchone() + if user: + print(f" [OK] 用户存在: {user[1]}") + else: + print(f" [ERROR] 用户不存在!") + + # 检查杯赛是否存在 + cursor.execute("SELECT id, name FROM contest WHERE id = ?", (contest_id,)) + contest = cursor.fetchone() + if contest: + print(f" [OK] 杯赛存在: {contest[1]}") + else: + print(f" [ERROR] 杯赛不存在!") + + print() + +conn.close() +print("检查完成") diff --git a/instance/database.db b/instance/database.db index 72519e4..9f7a9f3 100644 Binary files a/instance/database.db and b/instance/database.db differ diff --git a/migrate_db.py b/migrate_db.py new file mode 100644 index 0000000..ef6bc81 --- /dev/null +++ b/migrate_db.py @@ -0,0 +1,62 @@ +""" +数据库迁移脚本:为申请表添加拒绝次数控制字段 +""" +import sqlite3 +import os + +db_path = 'instance/database.db' + +if not os.path.exists(db_path): + print(f"错误:找不到数据库文件 {db_path}") + exit(1) + +conn = sqlite3.connect(db_path) +cursor = conn.cursor() + +print("开始数据库迁移...") + +# 检查并更新 teacher_application 表 +print("\n检查 teacher_application 表...") +cursor.execute("PRAGMA table_info(teacher_application)") +columns = [row[1] for row in cursor.fetchall()] +print(f"现有列: {columns}") + +if 'rejection_count' not in columns: + print("添加 rejection_count 字段...") + cursor.execute("ALTER TABLE teacher_application ADD COLUMN rejection_count INTEGER DEFAULT 0") + print("[OK] 已添加 rejection_count 字段") +else: + print("[OK] rejection_count 字段已存在") + +if 'last_rejected_at' not in columns: + print("添加 last_rejected_at 字段...") + cursor.execute("ALTER TABLE teacher_application ADD COLUMN last_rejected_at DATETIME") + print("[OK] 已添加 last_rejected_at 字段") +else: + print("[OK] last_rejected_at 字段已存在") + +# 检查并更新 contest_application 表 +print("\n检查 contest_application 表...") +cursor.execute("PRAGMA table_info(contest_application)") +columns = [row[1] for row in cursor.fetchall()] +print(f"现有列: {columns}") + +if 'rejection_count' not in columns: + print("添加 rejection_count 字段...") + cursor.execute("ALTER TABLE contest_application ADD COLUMN rejection_count INTEGER DEFAULT 0") + print("[OK] 已添加 rejection_count 字段") +else: + print("[OK] rejection_count 字段已存在") + +if 'last_rejected_at' not in columns: + print("添加 last_rejected_at 字段...") + cursor.execute("ALTER TABLE contest_application ADD COLUMN last_rejected_at DATETIME") + print("[OK] 已添加 last_rejected_at 字段") +else: + print("[OK] last_rejected_at 字段已存在") + +conn.commit() +conn.close() + +print("\n[SUCCESS] 数据库迁移完成!") +print("现在可以正常使用申请功能了。") diff --git a/templates/admin_teacher_applications.html b/templates/admin_teacher_applications.html index 7c69399..411809f 100644 --- a/templates/admin_teacher_applications.html +++ b/templates/admin_teacher_applications.html @@ -4,7 +4,30 @@ {% block admin_content %}
暂无待审核的教师申请
+ {% if session.user.role != 'admin' %} +您只能看到自己负责的杯赛的教师申请。如果有新的申请提交,会在此处显示。
+ {% endif %} +