From 10bbc40117d7b11c553dd422f4c1613d69e1749d Mon Sep 17 00:00:00 2001 From: guimoz Date: Mon, 30 Jan 2017 10:30:26 +0100 Subject: [PATCH] Affichage de l'historique plus souvent --- roulette.py | 57 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/roulette.py b/roulette.py index 8fdc401..fff5342 100644 --- a/roulette.py +++ b/roulette.py @@ -357,12 +357,47 @@ def home(): player = get_player_from_ip(get_ip()) if DEBUG: print(STATE) - if "down" in STATE: - return render_template('down.html', user=player,stats=statistiques()) - elif "up" in STATE: - if DEBUG: - print(player, 'arrived') + if DEBUG: + print(player, 'arrived') + bans = sorted(get_bans(player['id']), \ + key=lambda ban: ban['time'], \ + reverse=True) + bans_hist = [] + for ban in bans: + date = strftime('%Hh%M (%A)', localtime(ban['time'])) + source = get_player(ban['player_id']) + target = get_player(ban['target_id']) + + if target['id'] == player['id']: + if ban['success']: + entry = ('ban', u'%s : %s %s a réussi à t\'avoir.' \ + % (date, source['firstname'], source['name'])) + else: + entry = ('warn', u'%s : %s %s a essayé de te trancher, en vain.' \ + % (date, source['firstname'], source['name'])) + else: + if ban['success']: + entry = ('ok', u'%s : Tu as tranché %s %s avec succès.' \ + % (date, target['firstname'], target['name'])) + else: + entry = ('ban', u'%s : Tu as échoué en voulant trancher %s %s.' \ + % (date, target['firstname'], target['name'])) + bans_hist.append(entry) + + if "down" in STATE: + return render_template('down.html', user=player, stats=statistiques(), bans_hist=bans_hist) + elif "up" in STATE: + return render_template('home.html', bans_hist=bans_hist, stats=statistiques()) + else: + return render_template('precampagne.html', user=player,stats=statistiques()) + +@app.route('/jouer', methods=['GET', 'POST']) +@playable_required +def play(): + ip = get_ip() + player = get_player_from_ip(ip) + if "down" in STATE: bans = sorted(get_bans(player['id']), \ key=lambda ban: ban['time'], \ reverse=True) @@ -387,19 +422,9 @@ def home(): else: entry = ('ban', u'%s : Tu as échoué en voulant trancher %s %s.' \ % (date, target['firstname'], target['name'])) - bans_hist.append(entry) - return render_template('home.html', bans_hist=bans_hist, stats=statistiques()) - else: - return render_template('precampagne.html', user=player,stats=statistiques()) - -@app.route('/jouer', methods=['GET', 'POST']) -@playable_required -def play(): - ip = get_ip() - player = get_player_from_ip(ip) - if "down" in STATE: return render_template('down.html', user=player,stats=statistiques()) + elif "up" in STATE: # Traitement de la requête de bannissement if request.method == 'POST':