Changing database structure

This commit is contained in:
Denis-Cosmin Nutiu 2017-04-13 22:37:56 +03:00
parent 16d7b37cb2
commit c47ba2a2fa
4 changed files with 36 additions and 7 deletions

View file

@ -19,6 +19,7 @@ from src.models import db
from views.errors import error_pages from views.errors import error_pages
from views.scoreboard import scoreboard from views.scoreboard import scoreboard
from config import config from config import config
import flask_bootstrap
import flask import flask
@ -26,9 +27,9 @@ def create_app(config_name):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.config.from_object(config[config_name]) app.config.from_object(config[config_name])
config[config_name].init_app(app)
db.init_app(app) db.init_app(app)
config[config_name].init_app(app)
flask_bootstrap.Bootstrap(app)
app.register_blueprint(scoreboard) app.register_blueprint(scoreboard)
app.register_blueprint(error_pages) app.register_blueprint(error_pages)

View file

@ -26,11 +26,15 @@ class Result(db.Model):
""" """
__tablename__ = 'results' __tablename__ = 'results'
id = db.Column(db.Integer, primary_key=True) 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) score = db.Column(db.Integer)
def __init__(self, text=None, score=0): def __init__(self, gpu=None, cpu=None, log=None, score=0):
self.text = text self.gpu = gpu
self.cpu = cpu
self.log = log
self.score = score self.score = score
def __repr__(self): def __repr__(self):

22
src/templates/mybase.html Normal file
View file

@ -0,0 +1,22 @@
{% extends "bootstrap/base.html" %}
{% block title %}Scoreboard!{% endblock %}
{% block metas %}
<meta charset="UTF-8">
<meta name="author" content="Metonymy">
<meta name="description" content="The scoreboard for the benchmarks!">
<meta name="keywords" content="flask python metonymyqt benchmark scoreboard">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% endblock %}
<header>
{% block header %}
{% endblock %}
</header>
<main>
{% block main %}
{% endblock %}
</main>
<footer>
Copyright 2017 Fellowship of the Bits
</footer>

View file

@ -27,14 +27,16 @@ scoreboard = flask.Blueprint('scoreboard', __name__, template_folder='templates'
def upload(): def upload():
content = flask.request.get_json() content = flask.request.get_json()
try: 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']) score = int(content['score'])
except KeyError: # Json doesn't contain the keys we need. except KeyError: # Json doesn't contain the keys we need.
return json.dumps({'success': False}), 400, {'ContentType': 'application/json'} return json.dumps({'success': False}), 400, {'ContentType': 'application/json'}
except TypeError: # The types from the json object are not correct. except TypeError: # The types from the json object are not correct.
return json.dumps({'success': False}), 400, {'ContentType': 'application/json'} 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.add(entry)
db.session.commit() db.session.commit()