Browse Source

Added rollback, fixed interactions.

master
parent
commit
fc01ae952c
  1. 55
      app.py
  2. 1
      config_log.json
  3. 2
      requirements.txt
  4. 5
      templates/form.html
  5. 23
      templates/rollback.html

55
app.py

@ -6,9 +6,11 @@ import sys
import logging
import datetime
import toml
import os
SECRET_KEY = '!Êrû÷FwÙxIER'
CONFIG_FILE = 'config.toml'
CONFIG_LOG_FILE = 'config_log.json'
@ -36,6 +38,21 @@ order.append({"id":"t", "value":"Třezalka"})
order.append({"id":"n", "value":"Neběžel"})
def log_state(config):
with open(CONFIG_LOG_FILE) as f:
log = json.load(f)
if type(log) != list:
raise ValueError('Config log file must contain list!')
log.append(config)
os.rename(CONFIG_LOG_FILE,CONFIG_LOG_FILE+'.old')
with open(CONFIG_LOG_FILE,'w') as f:
json.dump(log,f)
log_state(config)
def check_form(form,config):
errors = []
for t in config["teams"]:
@ -48,11 +65,11 @@ def check_form(form,config):
def team_points(per1,order1,per2,order2,config):
# FIXME hardcoded interactions
if (per1 == 'Kodein' and per2 == 'Paralen') or \
(per1 == 'Penicilin' and per2 == 'Strepsils'):
# FIXME co třezalka?
order1 = min(order1,order2)
order2 = min(order1,order2)
if (per1 not in ['n','t'] and per2 not in ['n','t']) and \
((per1 == 'Kodein' and per2 == 'Paralen') or \
(per1 == 'Penicilin' and per2 == 'Strepsils')):
order1 = min(int(order1),int(order2))
order2 = order1
pts = 0
# Pokud neběžel první, neběžel ani druhý
@ -81,17 +98,6 @@ def team_points(per1,order1,per2,order2,config):
pts += config['base_pts']*config['order_coeff'][int(order2)]*org['coeff']
return pts
def get_person(form,tid,pid,config):
for org in config["orgs"]:
if form["clovek{}_{}_{}".format(pid,tid,org["id"])] == "true":
return org["id"]
return None
def get_team_by_id(aid,config):
for t in config["teams"]:
if t["id"] == aid:
return t
def get_org_by_id(aid,config):
for o in config["orgs"]:
if o["id"] == aid:
@ -136,12 +142,14 @@ def form_page():
team["points"] = 100
team['emerg_remain'] -= 1
config["round"] += 1
log_state(config)
return render_template("form.html",
round = config["times"][config['round']],
people = config["orgs"],
order = order,
teams = config["teams"],
errors = []
errors = [],
success = True
)
@ -150,3 +158,16 @@ def form_page():
def tablo():
return render_template("tablo.html",teams=config["teams"])
@app.route('/rollback',methods=['GET','POST'])
def rollback():
global config
with open(CONFIG_LOG_FILE) as f:
log = json.load(f)
if request.method == 'GET':
return render_template("rollback.html",log=log)
if request.method == 'POST':
version = request.form['version']
config = log[int(version)]
return render_template('rollback.html',log=log,success=True)

1
config_log.json

@ -0,0 +1 @@
[]

2
requirements.txt

@ -0,0 +1,2 @@
flask
toml

5
templates/form.html

@ -6,12 +6,17 @@
<body>
<h1>Zadávání pořadí - {{round}}</h1>
<form method="post" action="">
{% if errors %}
<h2> Problémy </h2>
<ul>
{% for e in errors %}
<li>{{e}}</li>
{% endfor %}
</ul>
{% endif %}
{% if success %}
<p class="success">Pořadí úspěšně zadáno</p>
{% endif %}
<div class="teams">
{% for team in teams %}
<div class="team">

23
templates/rollback.html

@ -0,0 +1,23 @@
<html>
<head>
<link rel="stylesheet" href="/static/style.css">
<title>Návrat k předchozí verzi</title>
</head>
<body>
{% if success %}
<p class="success"> Verze úspěšně změněna</p>
{% endif %}
<h1>Vyberte stav</h1>
<form method="post" action="">
<ul>
{% for l in log %}
<li>
<input type="radio" name="version" id="version_{{loop.index0}}" value="{{loop.index0}}">
<label for="version_{{loop.index0}}">{{l.times[l.round]}}</label>
</li>
{% endfor %}
</ul>
<input type="submit" value="Odeslat">
</form>
</body>
</html>
Loading…
Cancel
Save