Adding a new string value to the model: name
This commit is contained in:
parent
646b7bdadd
commit
a8bb3b15c3
5 changed files with 11 additions and 6 deletions
|
@ -26,12 +26,14 @@ class Result(db.Model):
|
|||
"""
|
||||
__tablename__ = 'results'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(50))
|
||||
gpu = db.Column(db.String(256))
|
||||
cpu = db.Column(db.String(256))
|
||||
log = db.Column(db.String(10000))
|
||||
score = db.Column(db.Integer)
|
||||
|
||||
def __init__(self, gpu=None, cpu=None, log=None, score=0):
|
||||
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=0):
|
||||
self.name = name
|
||||
self.gpu = gpu
|
||||
self.cpu = cpu
|
||||
self.log = log
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{{ super() }}
|
||||
|
||||
<div class="page-header">
|
||||
<h1>Result number #{{ name.id }} <small>Yeeeah!</small></h1>
|
||||
<h1>Result number #{{ name.id }} <small>Yeeeah! ({{name.name}})</small></h1>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<h4>Uploading Data</h4>
|
||||
<p>Uploading data is simple, all you need to is send a POST request with content-type <code>application/json</code> to <code>/result</code>.</p>
|
||||
<p>Your JSON must respect all the required fields.</p>
|
||||
<p>Example: <code>curl -H "Content-Type: application/json" -X POST -d '{"gpu":"GPU DUMMY TEXT","cpu":"CPU DUMMY TEXT","log":"So this will be a detailed log.","score": 1}' http://localhost:5000/result</code></p>
|
||||
<p>Example: <code>curl -H "Content-Type: application/json" -X POST -d '{"name":"Anonymous", "gpu":"GPU DUMMY TEXT","cpu":"CPU DUMMY TEXT","log":"So this will be a detailed log.","score": 1}' http://localhost:5000/result</code></p>
|
||||
<p>If the resource has been added sucessfully then the status code of <code>201</code> is returned.</p>
|
||||
<p>The <code>name</code> field can be used with the build in search functionality to search for your own results.</p>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -46,15 +46,16 @@ def result_post():
|
|||
"""
|
||||
content = flask.request.get_json()
|
||||
error = None
|
||||
gpu = cpu = log = score = None
|
||||
gpu = cpu = log = score = name = None
|
||||
|
||||
try:
|
||||
name = content['name']
|
||||
gpu = content['gpu']
|
||||
cpu = content['cpu']
|
||||
log = content['log']
|
||||
score = int(content['score'])
|
||||
except KeyError: # Json doesn't contain the keys we need.
|
||||
error = "invalid json keys: gpu, cpu, log, score"
|
||||
error = "invalid json keys: gpu, cpu, log, score name"
|
||||
except TypeError: # The types from the json object are not correct.
|
||||
error = "invalid json object"
|
||||
|
||||
|
@ -62,7 +63,7 @@ def result_post():
|
|||
return flask.jsonify({'error': error, 'success': False}), 400
|
||||
|
||||
# Add data to the database
|
||||
entry = Result(gpu=gpu, cpu=cpu, log=log, score=score)
|
||||
entry = Result(name=name, gpu=gpu, cpu=cpu, log=log, score=score)
|
||||
db.session.add(entry)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ class ScoreboardTestCase(unittest.TestCase):
|
|||
|
||||
def test_add_entry(self):
|
||||
data = dict(
|
||||
name="Test",
|
||||
gpu="CpuTesting2",
|
||||
cpu="GPUTesting2",
|
||||
log="This is a logfile",
|
||||
|
|
Loading…
Reference in a new issue