mobile app apply_contest contest_detail contest_edit notifications theme
This commit is contained in:
19
app.py
19
app.py
@@ -914,6 +914,12 @@ def api_change_name():
|
||||
@login_required
|
||||
def apply_contest():
|
||||
if request.method == 'POST':
|
||||
user_id = session['user']['id']
|
||||
# 防止重复提交:如果已有 pending 状态的申请,不允许再提交
|
||||
existing = ContestApplication.query.filter_by(user_id=user_id, status='pending').first()
|
||||
if existing:
|
||||
flash('您已有一个待审核的杯赛申请,请等待审核结果后再提交新申请')
|
||||
return redirect(url_for('contest_list'))
|
||||
name = request.form.get('name')
|
||||
organizer = request.form.get('organizer')
|
||||
description = request.form.get('description')
|
||||
@@ -1136,6 +1142,19 @@ def api_mark_all_notifications_read():
|
||||
db.session.commit()
|
||||
return jsonify({'success': True})
|
||||
|
||||
@app.route('/api/notifications/<int:nid>', methods=['DELETE'])
|
||||
@login_required
|
||||
def api_delete_notification(nid):
|
||||
"""删除单条通知(仅管理员可删除已处理的通知)"""
|
||||
n = Notification.query.get_or_404(nid)
|
||||
if n.user_id != session['user']['id']:
|
||||
return jsonify({'success': False, 'message': '无权操作'}), 403
|
||||
if session['user'].get('role') != 'admin':
|
||||
return jsonify({'success': False, 'message': '仅管理员可删除通知'}), 403
|
||||
db.session.delete(n)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True})
|
||||
|
||||
@app.route('/notifications')
|
||||
@login_required
|
||||
def notifications_page():
|
||||
|
||||
Reference in New Issue
Block a user