summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-01-13 18:14:17 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-01-13 18:14:17 +0000
commit80e83a1d91397d2c94c9c7dfcf504bb9797a2287 (patch)
tree66b2d66c8f2f420123050c1d0ecdc992960ab82e
parent824d8dd33dd4486d9bc27b22458a2aa752d16b47 (diff)
continued work on re-enabling the web interface
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@177 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py179
-rw-r--r--kpov_judge/web/kpov_judge/templates/index.html2
-rw-r--r--kpov_judge/web/kpov_judge/templates/task.html27
3 files changed, 119 insertions, 89 deletions
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index 627ff06..6b1f144 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -16,15 +16,16 @@ dummy_task = """
def task(neznano_ime_naloge):
print "Ta naloga ne obstaja!"
return {'odgovor': 'neznana naloga'}
-"""
-dummy_checker = """
def task_check(results, params):
raise Exception("neznana naloga?")
return "Manjka preverjalnik naloge (neznana naloga?)"
-"""
-dummy_meta = {'neznano_ime_naloge': {'opis':'NEZNANA NALOGA', 'w': False}}
+def gen_params(user_id, meta):
+ return dict()
+
+params_meta = {'neznano_ime_naloge': {'opis':'NEZNANA NALOGA', 'w': False}}
+"""
@app.before_request
def before_request():
@@ -52,55 +53,66 @@ def auth_greeting():
student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
return "To je past!" + str(flask.app.request.__dict__)
-@app.route('/<task_id>/results.json', methods=['GET', 'POST'])
-def results(task_id):
+def results_post(task_id, results):
+ db = g.db
+ params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})
+ if params is None:
+ params = dict()
+ else:
+ params = params['params']
+ user_params = json.loads(flask.app.request.form['params'])
+ meta = db.task_params_meta.find_one({'task_id': task_id})
+ if meta is None:
+ meta = dict()
+ else:
+ meta = meta['params']
+ for param_name, param_meta in meta.iteritems():
+ if param_meta.get('w', False) and param_name in user_params:
+ params[param_name] = user_params[param_name]
+ task_check_source = db.task_checkers.find_one({'task_id':task_id})
+ if task_check_source is None:
+ task_check_source = dummy_checker
+ else:
+ task_check_source = task_check_source['source']
+ try:
+ task_check_code = compile(task_check_source, 'checker.py', 'exec')
+ exec(task_check_code)
+ res = task_check(results, params)
+ except Exception, e:
+ res = "Checker crashed: " + str(e)
+ # flask.app.logger.error(str(e))
+ if (type(res) is int and res > 0):
+ res_status = 'OK'
+ else:
+ res_status = 'NOT OK'
+ db.results.insert({'task_id': task_id, 'result': res, 'status': res_status,'student_id': student_id, 'response': results, 'time': datetime.datetime.now()})
+ return {'result': res, 'status': res_status}
+
+def results_dict(task_id):
student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
- db = g.db
+ db = g.db
+ try:
+ entry = db.results.find_one(
+ {'$query': {'task_id': task_id, 'student_id': student_id},
+ '$orderby': {'status': -1}},
+ {'result': 1, 'status': 1, '_id': 0})
+ if entry is None:
+ return {'result': 'Naloga ni bila nikdar ocenjena', 'status': 'NOT OK'}
+ return entry
+ except Exception, e:
+ return {'Error': str(e)}
+ # flask.app.logger.error(str(e))
+ return {'result':"Mama! Zakaj si me zapustila? Sedaj se bom razstrelil."}
+
+@app.route('/tasks/<task_id>/results.json', methods=['GET', 'POST'])
+def results_json(task_id):
if flask.app.request.method == 'POST':
- results = json.loads(flask.app.request.form['results'])
- params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})
- if params is None:
- params = dict()
- else:
- params = params['params']
- user_params = json.loads(flask.app.request.form['params'])
- meta = db.task_params_meta.find_one({'task_id': task_id})
- if meta is None:
- meta = dict()
- else:
- meta = meta['params']
- for param_name, param_meta in meta.iteritems():
- if param_meta.get('w', False) and param_name in user_params:
- params[param_name] = user_params[param_name]
- task_check_source = db.task_checkers.find_one({'task_id':task_id})
- if task_check_source is None:
- task_check_source = dummy_checker
- else:
- task_check_source = task_check_source['source']
- try:
- task_check_code = compile(task_check_source, 'checker.py', 'exec')
- exec(task_check_code)
- res = task_check(results, params)
- except Exception, e:
- res = "Checker crashed: " + str(e)
- # flask.app.logger.error(str(e))
- if (type(res) is int and res > 0):
- res_status = 'OK'
- else:
- res_status = 'NOT OK'
- db.results.insert({'task_id': task_id, 'result': res, 'status': res_status,'student_id': student_id, 'response': results, 'time': datetime.datetime.now()})
- return json.dumps({'result': res, 'status': res_status})
- else:
- try:
- entry = db.results.find_one({'$query': {'task_id': task_id, 'student_id': student_id}, '$orderby': {'status': -1}},
- {'result': 1, 'status': 1, '_id': 0})
- if entry is None:
- return json.dumps({'result': 'Naloga ni bila nikdar ocenjena', 'status': 'NOT OK'})
- return json.dumps(entry)
- except Exception, e:
- return json.dumps({'Error': str(e)})
- # flask.app.logger.error(str(e))
- return json.dumps({'result':"Mama! Zakaj si me zapustila? Sedaj se bom razstrelil."})
+ results_post(task_id, json.loads(flask.app.request.form['results']))
+ return json.dumps(results_dict(task_id))
+
+@app.route('/tasks/<task_id>/<lang>/results.html', methods=['GET'])
+def results_html(task_id, lang):
+ return render_template('results.html', results=results_dict(task_id))
def public_meta(db, task_id):
shown = dict()
@@ -116,15 +128,19 @@ def public_meta(db, task_id):
shown = dummy_meta
return shown
-@app.route('/<task_id>/task.py', methods=['GET'])
+
+@app.route('/tasks/<task_id>/task.py', methods=['GET'])
def task_source(task_id):
db = g.db
try:
task_str = db.tasks.find_one({'task_id': task_id})['source']
- meta_str = '\nparam_meta = ' + str(public_meta(db, task_id))
except:
- return dummy_task + '\nparam_meta = ' + str(dummy_meta)
- return task_str + meta_str
+ return dummy_task
+ return task_str
+
+@app.route('/tasks/<task_id>/task.html', methods=['GET', 'POST'])
+def task_html(task_id):
+ return render_template('task.html', task=task_source(task_id))
def get_params(task_id, student_id, db):
try:
@@ -158,12 +174,26 @@ def get_params(task_id, student_id, db):
params = params['params']
return params, meta
-@app.route('/<task_id>/', methods = ['GET'])
-def task_greeting(task_id):
+@app.route('/tasks/<task_id>/', methods = ['GET'])
+def task_lang_redirect(task_id):
+ return redirect(url_for('task_greeting', task_id = task_id,
+ lang=app.config['DEFAULT_LANG']))
+
+@app.route('/tasks/<task_id>/<lang>/', methods = ['GET'])
+def task_greeting(task_id, lang):
student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
db = g.db
# generate the parameters as soon as the student visits
params, meta = get_params(task_id, student_id, db)
+ try:
+ instructions = db.task_instructions.find({'task_id': task_id})[0]
+ instructions = instructions.get(lang,
+ app.config['DEFAULT_LANG'])
+ except:
+ try:
+ instructions = instructions.values()[0]
+ except Exception, e:
+ instructions = str(e)
computer_list = db.student_computers.find({'task_id':task_id, 'student_id': student_id})
if request.args.get('narediStack', 'false') == 'true':
#db.student_tasks.update({'task_id':task_id, 'student_id': student_id}, {'$set': {'create_openstack': True}}, upsert = True)
@@ -175,10 +205,10 @@ def task_greeting(task_id):
openstackCreated = True
else:
openstackCreated = False
- return render_template('task.html', computers = computer_list, openstack = openstackCreated)
+ return render_template('task_greeting.html', computers = computer_list, lang=lang, openstack = openstackCreated, instructions=instructions)
-@app.route('/<task_id>/params.json', methods=['GET', 'POST'])
-def params(task_id):
+@app.route('/tasks/<task_id>/params.json', methods=['GET', 'POST'])
+def params_json(task_id):
student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
db = g.db
params, meta = get_params(task_id, student_id, db)
@@ -200,10 +230,35 @@ def params(task_id):
db.task_params.update({'task_id':task_id, 'student_id':student_id}, {'$set': {'params': params}}, upsert=True)
return json.dumps(shown_params)
-@app.route('/<task_id>/params_meta.json', methods=['GET'])
+@app.route('/tasks/<task_id>/<lang>/params.html', methods=['GET', 'POST'])
+def params_html(task_id, lang):
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ db = g.db
+ params, meta = get_params(task_id, student_id, db)
+ shown_params = dict()
+ for name, meta_param in meta.iteritems():
+ if meta_param.get('public', False):
+ shown_params[name] = params.get(name, '')
+ if flask.app.request.method == 'POST':
+ form = flask.app.request.form
+ new_params = dict()
+ for k, v in meta.iteritems():
+ if v.get('w', False):
+ params[k] = flask.app.request.form[k]
+ if v.get('public', False):
+ shown_params[name] = params.get(name, '')
+ db.task_params.update({'task_id':task_id, 'student_id':student_id}, {'$set': {'params': params}}, upsert=True)
+ return render_template('params.html', params=shown_params, params_meta = meta)
+
+
+@app.route('/tasks/<task_id>/params_meta.json', methods=['GET'])
def params_meta(task_id):
db = g.db
return json.dumps(public_meta(db, task_id))
+@app.route('/static/<path:filename>')
+def send_foo(filename):
+ return send_from_directory(app.config.STATIC_FILES, filename)
+
if __name__ == '__main__':
- app.run()
+ app.run(host='0.0.0.0')
diff --git a/kpov_judge/web/kpov_judge/templates/index.html b/kpov_judge/web/kpov_judge/templates/index.html
index c0c7924..2ceb378 100644
--- a/kpov_judge/web/kpov_judge/templates/index.html
+++ b/kpov_judge/web/kpov_judge/templates/index.html
@@ -7,7 +7,7 @@ Zdravo, {{student_id}}
Trenutno so na voljo naloge:
<ul>
{% for t in tasks %}
-<li><a href="{{t}}">{{t}}</a></li>
+<li><a href="tasks/{{t}}">{{t}}</a></li>
{% endfor %}
</ul>
</li>
diff --git a/kpov_judge/web/kpov_judge/templates/task.html b/kpov_judge/web/kpov_judge/templates/task.html
index 11fd541..98147ab 100644
--- a/kpov_judge/web/kpov_judge/templates/task.html
+++ b/kpov_judge/web/kpov_judge/templates/task.html
@@ -4,32 +4,7 @@
{{task_id}}
</h1>
<p>
-<h2>Računalniki v vaji</h2>
-{% for c in computers %}
- <h3>{{c['name']}}</h3>
- {% if 'disk_urls' in c %}
- <ul>
- {% for u in c['disk_urls'] %}
- <li><a href={{u['url']}}>{{u['name']}}</a></li>
- {% endfor %}
- </ul>
- {% else %}
- Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.
- {% endif %}
-{% endfor %}
+<pre>{{task}}</pre>
</p>
-<p>
-Lahko si ogledate surove:
-<a href='results.json'>rezultate</a>
-<a href='params.json'>parametre</a>
-<a href='params_meta.json'>opise parametrov</a>
-<a href='task.py'>preverjalni program</a>
-</p>
-<p>
-{% if openstack %}
-Openstack projekt za to vajo je že ustvarjen ali v izdelavi (funkcionalnost še ne deluje).
-{% else %}
-<a href='?narediStack=true'>Ustvari</a> Openstack projekt za to vajo (funkcionalnost še ne deluje).
-{% endif %}
</body>
</html>