diff --git a/main.py b/main.py index 3541188..d3b1fca 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,7 @@ async def require_admin(request: Request): return payload -app = FastAPI(title='文艺汇演评分系统', description='乌鲁木齐群众文化艺术展评') +app = FastAPI() app.add_middleware( CORSMiddleware, @@ -102,6 +102,28 @@ def init_db(): ('admin_001', 'admin', 'admin123', datetime.now()), ) + cursor.execute("SELECT COUNT(*) FROM settings WHERE key = 'main_title'") + if cursor.fetchone()[0] == 0: + cursor.execute( + "INSERT INTO settings (key, value) VALUES ('main_title', '文化艺术展评'), ('sub_title', '文艺汇演')" + ) + + cursor.execute('SELECT COUNT(*) FROM batches') + if cursor.fetchone()[0] == 0: + batches_data = [] + cursor.executemany( + 'INSERT INTO batches (name, created_at) VALUES (?, ?)', + batches_data, + ) + + cursor.execute('SELECT COUNT(*) FROM judges') + if cursor.fetchone()[0] == 0: + judges_data = [] + cursor.executemany( + 'INSERT INTO judges (id, name, order_num, created_at) VALUES (?, ?, ?, ?)', + judges_data, + ) + cursor.execute("SELECT COUNT(*) FROM settings WHERE key = 'award_first'") if cursor.fetchone()[0] == 0: cursor.execute( @@ -114,37 +136,6 @@ def init_db(): "INSERT INTO settings (key, value) VALUES ('award_first_name', '一等奖'), ('award_second_name', '二等奖'), ('award_third_name', '三等奖')" ) - cursor.execute("SELECT COUNT(*) FROM settings WHERE key = 'main_title'") - if cursor.fetchone()[0] == 0: - cursor.execute( - "INSERT INTO settings (key, value) VALUES ('main_title', '乌鲁木齐群众文化艺术展评'), ('sub_title', '“建农杯”文艺汇演')" - ) - - cursor.execute('SELECT COUNT(*) FROM batches') - if cursor.fetchone()[0] == 0: - cursor.execute( - 'INSERT INTO batches (name, created_at) VALUES (?, ?)', - ('第一批次', datetime.now()), - ) - cursor.execute( - 'INSERT INTO batches (name, created_at) VALUES (?, ?)', - ('第二批次', datetime.now()), - ) - - cursor.execute('SELECT COUNT(*) FROM judges') - if cursor.fetchone()[0] == 0: - judges_data = [ - ('P.01', '王飞翔', 1, datetime.now()), - ('P.02', '冯建农', 2, datetime.now()), - ('P.03', '张宁', 3, datetime.now()), - ('P.04', '沈澜涛', 4, datetime.now()), - ('P.05', '龚楠', 5, datetime.now()), - ] - cursor.executemany( - 'INSERT INTO judges (id, name, order_num, created_at) VALUES (?, ?, ?, ?)', - judges_data, - ) - init_db() @@ -303,8 +294,8 @@ async def get_title_settings(): ) titles = {row['key']: row['value'] for row in cursor.fetchall()} return { - 'main_title': titles.get('main_title', '乌鲁木齐群众文化艺术展评'), - 'sub_title': titles.get('sub_title', '“建农杯”文艺汇演'), + 'main_title': titles.get('main_title', ''), + 'sub_title': titles.get('sub_title', ''), } @@ -1769,7 +1760,7 @@ HTML_TEMPLATE = """ async function renderAdminScoringTable() { if(!judgesData.length || !programsData.length){ - document.getElementById('adminScoringContainer').innerHTML = '