Changing database structure
This commit is contained in:
parent
16d7b37cb2
commit
c47ba2a2fa
4 changed files with 36 additions and 7 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
22
src/templates/mybase.html
Normal file
22
src/templates/mybase.html
Normal 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>
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue