mobile database admin_teacher_applications check_applications migrate test_owner_access themes

This commit is contained in:
2026-02-28 13:31:32 +08:00
parent 13057c8757
commit 695c84b4cf
5 changed files with 204 additions and 1 deletions

50
check_applications.py Normal file
View File

@@ -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("检查完成")

Binary file not shown.

62
migrate_db.py Normal file
View File

@@ -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("现在可以正常使用申请功能了。")

View File

@@ -4,7 +4,30 @@
{% block admin_content %}
<div class="space-y-6">
<h1 class="text-2xl font-bold text-slate-900">教师申请审核</h1>
<div class="flex items-center justify-between">
<h1 class="text-2xl font-bold text-slate-900">教师申请审核</h1>
<div class="text-sm text-slate-500">
{% if session.user.role == 'admin' %}
<span class="px-3 py-1 bg-indigo-100 text-indigo-700 rounded-full font-medium">管理员视图</span>
{% else %}
<span class="px-3 py-1 bg-purple-100 text-purple-700 rounded-full font-medium">杯赛负责人视图</span>
{% endif %}
</div>
</div>
{% if apps|length == 0 %}
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4 text-sm text-blue-800">
<div class="flex items-start gap-3">
<svg class="w-5 h-5 flex-shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
<div>
<p class="font-medium mb-1">暂无待审核的教师申请</p>
{% if session.user.role != 'admin' %}
<p class="text-blue-700">您只能看到自己负责的杯赛的教师申请。如果有新的申请提交,会在此处显示。</p>
{% endif %}
</div>
</div>
</div>
{% endif %}
<div class="bg-white shadow-sm rounded-lg border border-slate-200 overflow-hidden">
<table class="min-w-full divide-y divide-slate-200">

68
test_owner_access.py Normal file
View File

@@ -0,0 +1,68 @@
"""
测试杯赛负责人访问教师申请审批页面
"""
import sqlite3
db_path = 'instance/database.db'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
print("模拟杯赛负责人访问教师申请审批页面...\n")
# 获取一个杯赛负责人
cursor.execute("""
SELECT cm.user_id, u.name, u.role, cm.contest_id, c.name as contest_name
FROM contest_membership cm
JOIN user u ON cm.user_id = u.id
JOIN contest c ON cm.contest_id = c.id
WHERE cm.role = 'owner'
LIMIT 1
""")
owner = cursor.fetchone()
if not owner:
print("没有找到杯赛负责人")
conn.close()
exit()
user_id, user_name, user_role, contest_id, contest_name = owner
print(f"杯赛负责人信息:")
print(f" 用户ID: {user_id}")
print(f" 用户名: {user_name}")
print(f" 角色: {user_role}")
print(f" 负责杯赛ID: {contest_id}")
print(f" 杯赛名称: {contest_name}")
# 模拟查询该负责人能看到的申请
cursor.execute("""
SELECT cm.contest_id
FROM contest_membership cm
WHERE cm.user_id = ? AND cm.role = 'owner'
""", (user_id,))
owned_contests = [row[0] for row in cursor.fetchall()]
print(f"\n该用户负责的所有杯赛ID: {owned_contests}")
if owned_contests:
placeholders = ','.join('?' * len(owned_contests))
cursor.execute(f"""
SELECT ta.id, ta.user_id, ta.contest_id, ta.status, u.name, c.name
FROM teacher_application ta
JOIN user u ON ta.user_id = u.id
JOIN contest c ON ta.contest_id = c.id
WHERE ta.status = 'pending' AND ta.contest_id IN ({placeholders})
ORDER BY ta.applied_at DESC
""", owned_contests)
apps = cursor.fetchall()
print(f"\n该负责人能看到的待审批申请数: {len(apps)}")
if apps:
for app in apps:
print(f" 申请ID: {app[0]}, 申请人: {app[4]}, 杯赛: {app[5]}")
else:
print(" 暂无待审核的教师申请")
else:
print("\n该用户不负责任何杯赛")
conn.close()
print("\n测试完成")