From c47ba2a2fa485287dbe52ed7b490bf23c5b5c4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Thu, 13 Apr 2017 22:37:56 +0300 Subject: [PATCH] Changing database structure --- src/application.py | 5 +++-- src/models/__init__.py | 10 +++++++--- src/templates/mybase.html | 22 ++++++++++++++++++++++ src/views/scoreboard.py | 6 ++++-- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/templates/mybase.html diff --git a/src/application.py b/src/application.py index 0084cb2..147e320 100644 --- a/src/application.py +++ b/src/application.py @@ -19,6 +19,7 @@ from src.models import db from views.errors import error_pages from views.scoreboard import scoreboard from config import config +import flask_bootstrap import flask @@ -26,9 +27,9 @@ def create_app(config_name): app = flask.Flask(__name__) app.config.from_object(config[config_name]) - config[config_name].init_app(app) db.init_app(app) - + config[config_name].init_app(app) + flask_bootstrap.Bootstrap(app) app.register_blueprint(scoreboard) app.register_blueprint(error_pages) diff --git a/src/models/__init__.py b/src/models/__init__.py index 1a59cde..3b2cf7c 100644 --- a/src/models/__init__.py +++ b/src/models/__init__.py @@ -26,11 +26,15 @@ class Result(db.Model): """ __tablename__ = 'results' id = db.Column(db.Integer, primary_key=True) - text = db.Column(db.String(512)) + gpu = db.Column(db.String(256)) + cpu = db.Column(db.String(256)) + log = db.Column(db.String(4086)) score = db.Column(db.Integer) - def __init__(self, text=None, score=0): - self.text = text + def __init__(self, gpu=None, cpu=None, log=None, score=0): + self.gpu = gpu + self.cpu = cpu + self.log = log self.score = score def __repr__(self): diff --git a/src/templates/mybase.html b/src/templates/mybase.html new file mode 100644 index 0000000..5b4e8ad --- /dev/null +++ b/src/templates/mybase.html @@ -0,0 +1,22 @@ +{% extends "bootstrap/base.html" %} +{% block title %}Scoreboard!{% endblock %} +{% block metas %} + + + + + +{% endblock %} + + +
+ {% block header %} + {% endblock %} +
+
+ {% block main %} + {% endblock %} +
+ diff --git a/src/views/scoreboard.py b/src/views/scoreboard.py index 86f1c98..d59bb18 100644 --- a/src/views/scoreboard.py +++ b/src/views/scoreboard.py @@ -27,14 +27,16 @@ scoreboard = flask.Blueprint('scoreboard', __name__, template_folder='templates' def upload(): content = flask.request.get_json() try: - text = flask.escape(content['text']) + gpu = flask.escape(content['gpu']) + cpu = flask.escape(content['cpu']) + log = flask.escape(content['log']) score = int(content['score']) except KeyError: # Json doesn't contain the keys we need. return json.dumps({'success': False}), 400, {'ContentType': 'application/json'} except TypeError: # The types from the json object are not correct. return json.dumps({'success': False}), 400, {'ContentType': 'application/json'} - entry = Result(text=text, score=score) + entry = Result(gpu=gpu, cpu=cpu, log=log, score=score) db.session.add(entry) db.session.commit()