aboutsummaryrefslogtreecommitdiff
path: root/ustayml/__init__.py
blob: 9e57bc4ea932c1c5452f6304fec6d2d2bdf114cb (plain)
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
import os

from flask import Flask, render_template


def create_app(test_config=None):
    # Create app object.  Configuration files are relative to instance folder.
    app = Flask(__name__, instance_relative_config=True)

    # Config
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'ustayml.sqlite'),
        DATASET_PATH=os.path.join(app.instance_path, 'dataset'),
        STUDENT_DATA_PATH=os.path.join(app.instance_path, 'student'),
    )

    if test_config is None:
        app.config.from_pyfile('config.py', silent=True)
    else:
        app.config.from_mapping(test_config)

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    from . import db
    db.init_app(app)

    # Register functions and blueprints

    @app.route('/')
    def index():
        return render_template('index.html')

    from .views import (
        auth, 
        students, load_data, dashboard
    )
    app.register_blueprint(auth.bp)
    app.register_blueprint(students.bp)
    app.register_blueprint(load_data.bp)
    app.register_blueprint(dashboard.bp)

    # app.add_url_rule('/', endpoint='index')

    return app