diff --git a/src/application.py b/src/application.py index 7ce5d66..760503a 100644 --- a/src/application.py +++ b/src/application.py @@ -15,7 +15,8 @@ You should have received a copy of the GNU General Public License along with scoreboard-benchmark . If not, see . """ -import src.models.result +from src.models import Result +from src.models import db import flask import os @@ -28,18 +29,18 @@ basedir = os.path.abspath(os.path.dirname(__file__)) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.sqlite') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True -src.models.result.db.init_app(app) +db.init_app(app) @app.before_first_request def create_test_databases(): - src.models.result.db.drop_all() - src.models.result.db.create_all() - b1 = src.models.result.Result(text="asda", score=100) - b2 = src.models.result.Result(text="i7 flips flops", score=400) - src.models.result.db.session.add(b1) - src.models.result.db.session.add(b2) - src.models.result.db.session.commit() + db.drop_all() + db.create_all() + b1 = Result(text="asda", score=100) + b2 = Result(text="i7 flips flops", score=400) + db.session.add(b1) + db.session.add(b2) + db.session.commit() @app.route("/upload") @@ -49,7 +50,8 @@ def upload(): @app.route("/") def index(): - return flask.render_template("index.html") + results = Result.query.all() + return flask.render_template("index.html", results=results) @app.errorhandler(404) diff --git a/src/models/__init__.py b/src/models/__init__.py index a03fbe5..1a59cde 100644 --- a/src/models/__init__.py +++ b/src/models/__init__.py @@ -29,5 +29,9 @@ class Result(db.Model): text = db.Column(db.String(512)) score = db.Column(db.Integer) + def __init__(self, text=None, score=0): + self.text = text + self.score = score + def __repr__(self): return self.text