Updating application so it displays models on the front page
This commit is contained in:
parent
f06925d827
commit
76e7fa4894
2 changed files with 16 additions and 10 deletions
|
@ -15,7 +15,8 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with scoreboard-benchmark . If not, see <http://www.gnu.org/licenses/>.
|
along with scoreboard-benchmark . If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import src.models.result
|
from src.models import Result
|
||||||
|
from src.models import db
|
||||||
import flask
|
import flask
|
||||||
import os
|
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_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.sqlite')
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
|
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
|
||||||
src.models.result.db.init_app(app)
|
db.init_app(app)
|
||||||
|
|
||||||
|
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def create_test_databases():
|
def create_test_databases():
|
||||||
src.models.result.db.drop_all()
|
db.drop_all()
|
||||||
src.models.result.db.create_all()
|
db.create_all()
|
||||||
b1 = src.models.result.Result(text="asda", score=100)
|
b1 = Result(text="asda", score=100)
|
||||||
b2 = src.models.result.Result(text="i7 flips flops", score=400)
|
b2 = Result(text="i7 flips flops", score=400)
|
||||||
src.models.result.db.session.add(b1)
|
db.session.add(b1)
|
||||||
src.models.result.db.session.add(b2)
|
db.session.add(b2)
|
||||||
src.models.result.db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/upload")
|
@app.route("/upload")
|
||||||
|
@ -49,7 +50,8 @@ def upload():
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return flask.render_template("index.html")
|
results = Result.query.all()
|
||||||
|
return flask.render_template("index.html", results=results)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
|
|
|
@ -29,5 +29,9 @@ class Result(db.Model):
|
||||||
text = db.Column(db.String(512))
|
text = db.Column(db.String(512))
|
||||||
score = db.Column(db.Integer)
|
score = db.Column(db.Integer)
|
||||||
|
|
||||||
|
def __init__(self, text=None, score=0):
|
||||||
|
self.text = text
|
||||||
|
self.score = score
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
Loading…
Reference in a new issue