File size: 1,476 Bytes
4f591e5 33ff5ca 75fb515 4f591e5 75fb515 4f591e5 75fb515 4f591e5 75fb515 4f591e5 75fb515 4f591e5 75fb515 4f591e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from flask import render_template, redirect, url_for, request, flash
from flask_login import login_required, current_user
from . import dashboard_bp
from database import History, db
from create_app import *
@dashboard_bp.route('/dashboard', defaults={'page': 1})
@dashboard_bp.route('/dashboard/page/<int:page>')
@login_required # Use Flask-Login's decorator
def dashboard(page):
# Get user ID from current_user (Flask-Login)
user_id = current_user.id
per_page = 10
pagination = History.query.filter_by(user_id=user_id).order_by(History.created_at.desc()).paginate(
page=page, per_page=per_page, error_out=False
)
histories = pagination.items
return render_template(
'dashboard.html',
histories=histories,
pagination=pagination,
scores_tr=[h.score_tr for h in histories],
scores_cc=[h.score_cc for h in histories],
scores_lr=[h.score_lr for h in histories],
scores_gra=[h.score_gra for h in histories],
creation_times=[h.created_at.strftime('%Y-%m-%d %H:%M:%S') for h in histories]
)
@dashboard_bp.route('/delete_histories', methods=['POST'])
def delete_histories():
history_ids = request.form.getlist('history_ids')
History.query.filter(History.id.in_(history_ids), History.user_id == current_user.id).delete(synchronize_session=False)
db.session.commit()
flash('Selected histories deleted.')
return redirect(url_for('dashboard.dashboard'))
|