refactor: introduce app factory + blueprints (auth, core, admin users, invite); add utils and wsgi entrypoint; keep legacy routes for now
This commit is contained in:
54
app/blueprints/core.py
Normal file
54
app/blueprints/core.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from app.models import SurveyInvite, UserSurvey, SurveyType, User
|
||||
|
||||
bp = Blueprint('core', __name__)
|
||||
|
||||
|
||||
@bp.route('/', endpoint='home')
|
||||
def home():
|
||||
return redirect(url_for('choose_survey'))
|
||||
|
||||
|
||||
@bp.route('/dashboard', endpoint='dashboard')
|
||||
@login_required
|
||||
def dashboard():
|
||||
if current_user.is_admin:
|
||||
invites = (SurveyInvite
|
||||
.select()
|
||||
.join(UserSurvey)
|
||||
.order_by(SurveyInvite.sent_at.desc()))
|
||||
else:
|
||||
invites = (SurveyInvite
|
||||
.select()
|
||||
.join(UserSurvey)
|
||||
.where(UserSurvey.user == current_user.id)
|
||||
.order_by(SurveyInvite.sent_at.desc()))
|
||||
return render_template('user/dashboard.html', invites=invites, title='Отчёты')
|
||||
|
||||
|
||||
@bp.route('/quiz', endpoint='choose_survey')
|
||||
@login_required
|
||||
def choose_survey():
|
||||
if current_user.is_admin:
|
||||
surveys = SurveyType.select()
|
||||
users = User.select().where(User.is_admin == False)
|
||||
assignments = {
|
||||
s.id: [us.user.id for us in UserSurvey.select().where(UserSurvey.survey_type == s)]
|
||||
for s in surveys
|
||||
}
|
||||
else:
|
||||
surveys = (SurveyType
|
||||
.select()
|
||||
.join(UserSurvey)
|
||||
.where(UserSurvey.user == current_user.id)
|
||||
.distinct())
|
||||
users = []
|
||||
assignments = {}
|
||||
|
||||
return render_template('choose_survey.html',
|
||||
surveys=surveys,
|
||||
users=users,
|
||||
assignments=assignments,
|
||||
title='Опросы')
|
||||
|
||||
Reference in New Issue
Block a user