-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
64 lines (46 loc) · 2.09 KB
/
app.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import datetime
import jinja2.defaults
from auth import auth_bp
from user import user_bp
from course import course_bp
from config import config_bp
from course_preference import course_preference_bp
from assignment import assignment_bp
from db import db, Year, Organization, User, Course, Teacher, Researcher, Evaluation
from decorators import *
from flask import Flask, render_template, session, request
from enums import *
from util import get_current_year
import json
app = Flask(__name__)
app.config.from_file("config.json", load=json.load)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
# Core blueprints
app.register_blueprint(auth_bp, url_prefix="/auth")
app.register_blueprint(user_bp, url_prefix="/user")
app.register_blueprint(course_bp, url_prefix="/course")
app.register_blueprint(config_bp, url_prefix="/config")
app.register_blueprint(course_preference_bp, url_prefix="/course_preference")
app.register_blueprint(assignment_bp, url_prefix="/assignment")
def get_configurations():
return db.session.query(Year).order_by(Year.year.asc()).all()
def get_organization():
return db.session.query(Organization).all()
def is_researcher():
return db.session.query(Researcher).filter_by(user_id=session['user_id']).first() is not None
@app.context_processor
def inject_configurations():
return dict(configurations=get_configurations(), organizations_code=get_organization(), quadri=QUADRI,
language=LANGUAGES, researcher_type=RESEARCHERS_TYPE, dynamic_year=get_current_year(),
tasks=TASK, evaluation_hour=EVALUATION_HOUR, workloads=WORKLOAD, is_researcher=is_researcher())
# Routes
@app.route('/')
@login_required
def index(): # put application's code here
current_year = get_current_year()
user = db.session.query(User).filter_by(email=session['email']).first()
courses_teacher = db.session.query(Course).filter_by(year=current_year).join(Teacher).filter(Teacher.user_id == user.id).all()
return render_template("home.html", user=user, courses=courses_teacher, evaluations=user.evaluations)
if __name__ == '__main__':
app.run()