Commit a12542cd authored by Sli's avatar Sli

Refactoring + boutons de modification des quantités

parent cd94cc7e
......@@ -3,7 +3,7 @@
# @Author: klmp200
# @Date: 2016-07-03 17:57:28
# @Last Modified by: klmp200
# @Last Modified time: 2016-11-04 21:16:27
# @Last Modified time: 2016-11-05 18:49:18
from bottle import Bottle, static_file, request, template, redirect
from bottle.ext import sqlite
......@@ -63,34 +63,70 @@ def DisplayAdmin(db):
verifKey the verification key of the ticket
"""
table = []
form = {}
form['key'] = ""
form['id'] = ""
if request.query.verifKey:
request.query.verifKey = request.query.verifKey.upper()
form['key'] = request.query.verifKey
if request.query.id:
form['id'] = request.query.id
if not request.query.id and not request.query.verifKey:
table = db.execute('SELECT * from ticket').fetchall()
elif request.query.id and not request.query.verifKey:
table = db.execute('SELECT * from ticket where id=:id',
{"id": request.query.id}).fetchall()
elif not request.query.id and request.query.verifKey:
table = db.execute('SELECT * from ticket where verifKey=:key',
{"key": request.query.verifKey})
else:
table = db.execute('SELECT * from ticket where verifKey=:key and id=:id',
{"key": request.query.verifKey,
"id": request.query.id})
form = ObtainGetArgs(request.query, ['id', 'verifKey', 'ajax'])
form['verifKey'] = form['verifKey'].upper()
table = SearchDb(db, form)
# if not form['id'] and not form['verifKey']:
# table = db.execute('SELECT * from ticket').fetchall()
# elif form['id'] and not form['verifKey']:
# table = db.execute('SELECT * from ticket where id=:id',
# {"id": form['id']}).fetchall()
# elif not form['id'] and form['verifKey']:
# table = db.execute('SELECT * from ticket where verifKey=:key',
# {"key": form['verifKey']}).fetchall()
# else:
# table = db.execute('SELECT * from ticket where verifKey=:key and id=:id',
# {"key": form['verifKey'],
# "id": form['id']}).fetchall()
tickets = serialize_table(table)
tickets = tickets[::-1]
if request.query.ajax:
if form['ajax']:
return dict(data=tickets)
else:
return template('admin.simple', table=tickets, form=form)
def SearchDb(db, args):
if args['id'] or args['verifKey']:
table = db.execute("SELECT * from ticket where upper(verifKey) like :key or id =:id",
{"key": '%' + args['verifKey'] + '%',
"id": args['id']}).fetchall()
else:
table = db.execute('SELECT * from ticket').fetchall()
return table
def ObtainGetArgs(query, args):
"""
Fill a dict with get args in query
query : the query object
args : a list of get arguments to get
"""
getargs = {}
for arg in args:
if getattr(query, arg):
getargs[arg] = getattr(query, arg)
else:
getargs[arg] = ""
return getargs
@app.route('/edit/qt/<id_ticket>/<nb>')
def EditTicketQuantity(db, id_ticket, nb):
"""
Edit the quantity avaliable for a ticket
"""
nb = int(nb)
ticket = db.execute('SELECT * from ticket where id=:id',
{"id": id_ticket}).fetchone()
if ticket is not None:
nb_new = ticket['availablePlaces'] + nb
if nb_new >= 0 and nb_new <= ticket['totalPlaces']:
db.execute('UPDATE ticket SET availablePlaces=:av WHERE id=:id',
{"av": nb_new, "id": id_ticket})
redirect('/admin')
@app.route('/validate', method='POST')
def Validate(db):
......
......@@ -3,6 +3,7 @@
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="/media/css/pure-min.css">
<link rel="stylesheet" type="text/css" href="/media/css/colored-buttons.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
......@@ -16,7 +17,7 @@
Recherche par id :
<input type="text" name="id" value="{{form['id']}}"/>
Clef de vérification :
<input type="text" name="verifKey" value="{{form['key']}}"/>
<input type="text" name="verifKey" value="{{form['verifKey']}}"/>
<button type="submit" class="pure-button pure-button-primary">Rechercher</button>
</form>
<h2>Données</h2>
......@@ -26,6 +27,7 @@
<th>Clef de vérification</th>
<th>Places restantes</th>
<th>Places total disponible</th>
<th>Modifier quantité</th>
<th>Supprimer ticket</th>
</tr>
</thead>
......@@ -35,7 +37,11 @@
<td>{{element['verifKey']}}</td>
<td>{{element['availablePlaces']}}</td>
<td>{{element['totalPlaces']}}</td>
<td><a href='/delete/{{element["id"]}}' class="pure-button pure-button-primary">Supprimer</a></td>
<td>
<a href="/edit/qt/{{element['id']}}/1" class="button-success pure-button">+1</a>
<a href="/edit/qt/{{element['id']}}/-1" class="button-warning pure-button">-1</a>
</td>
<td><a href='/delete/{{element["id"]}}' class="button-error pure-button">Supprimer</a></td>
</tr>
% end
</tbody>
......@@ -75,7 +81,9 @@
to_write += "<td>" + ticket['verifKey'] + "</td>";
to_write += "<td>" + ticket['availablePlaces'] + "</td>";
to_write += "<td>" + ticket['totalPlaces'] + "</td>";
to_write += "<td><a href='/delete/" + ticket['id'] + "' class='pure-button pure-button-primary'>Supprimer</a></td>";
to_write += "<td><a href='/edit/qt/" + ticket['id'] + "/1' class='button-success pure-button'>+1</a>\n";
to_write += "<a href='/edit/qt/" + ticket['id'] + "/-1' class='button-warning pure-button'>-1</a></td>";
to_write += "<td><a href='/delete/" + ticket['id'] + "' class='button-error pure-button'>Supprimer</a></td>";
to_write += "</tr>";
});
$("#Tickets").empty();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment