Autocomplétion
This commit is contained in:
parent
79191a406e
commit
e16e4be753
2 changed files with 44 additions and 14 deletions
23
roulette.py
23
roulette.py
|
@ -10,6 +10,7 @@ import MySQLdb
|
|||
from time import time, localtime, strftime
|
||||
import locale
|
||||
import random
|
||||
import json
|
||||
|
||||
# configuration
|
||||
DEBUG = True
|
||||
|
@ -164,12 +165,9 @@ def get_players_not_banned():
|
|||
not_banned = [{'id': row[0], 'firstname': row[1], 'name': row[2]} for row in rows]
|
||||
|
||||
# Ensuite on applique les règles d'immunité
|
||||
with open(IMMUNITY_FILE, 'r') as f:
|
||||
immunity = f.read()
|
||||
result = []
|
||||
for user in not_banned:
|
||||
if user['firstname']+' '+user['name'] not in immunity:
|
||||
result.append(user)
|
||||
result = []
|
||||
for user in not_banned:
|
||||
result.append(user)
|
||||
return result
|
||||
|
||||
def cheat(player_id, target_id):
|
||||
|
@ -419,5 +417,18 @@ def play():
|
|||
else:
|
||||
return render_template('precampagne.html', user=player,stats=statistiques())
|
||||
|
||||
|
||||
@app.route('/complete')
|
||||
def complete():
|
||||
v = request.args['v']
|
||||
con = connect_sql()
|
||||
cur = con.cursor()
|
||||
cur.execute("""select id, firstname, name from players where
|
||||
name like "{value}%" or firstname like "{value}%";""".format(value=v))
|
||||
rows = [[i[0], i[1]+' '+i[2]] for i in cur.fetchall()]
|
||||
con.close()
|
||||
return json.dumps(rows)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
|
|
@ -1,19 +1,38 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<script>
|
||||
$(function(){
|
||||
$('#word').keyup(function(e){
|
||||
var input = $(this).val();
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "complete",
|
||||
data: {v: input},
|
||||
async: true,
|
||||
success: function(data){
|
||||
var outWords = $.parseJSON(data);
|
||||
$('#auto').html('');
|
||||
|
||||
for(x = 0; x < outWords.length; x++){
|
||||
$('#auto').prepend('<option value="' + outWords[x][0] + '">'+outWords[x][1]+'</option>'); //Fills the #auto div with the options
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<h2>Trancher un joueur</h2>
|
||||
<p>
|
||||
Ta cible sera notifiée quelle que soit l'issue de ta tentative. Question
|
||||
chance, c'est 50-50.
|
||||
</p>
|
||||
<form id="select" action="" method="post">
|
||||
<select name="target_id">
|
||||
<p><option value="none">(sélectionner un joueur)</option>
|
||||
{% for player in players %}
|
||||
<option value="{{ player.id }}">
|
||||
{{ "%s %s" % (player.firstname, player.name) }}
|
||||
</option></p>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<label for="word">Écrit le nom de ta victime </label>
|
||||
<input type="text" name="search" id="word">
|
||||
<label for="auto">et choisit-la :</label>
|
||||
<select id="auto" name="target_id">
|
||||
<option value="none">(sélectionner un joueur)</option>
|
||||
</select>
|
||||
<input type="submit" value="Tchak !" />
|
||||
</form>
|
||||
<h2>
|
||||
|
|
Loading…
Reference in a new issue