From 76e7fa48945a486c82b22ac547f901f23bf1d7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Thu, 13 Apr 2017 00:11:35 +0300 Subject: [PATCH] Updating application so it displays models on the front page --- src/application.py | 22 ++++++++++++---------- src/models/__init__.py | 4 ++++ 2 files changed, 16 insertions(+), 10 deletions(-) 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