Commit dba7fccb authored by Sli's avatar Sli

Ajout de dates, refactoring, documentation et ajout d'un tutoriel

parent a12542cd
......@@ -2,5 +2,6 @@ CREATE Table ticket (
id INTEGER PRIMARY KEY AUTOINCREMENT,
verifKey TEXT UNIQUE NOT NULL,
availablePlaces INTEGER NOT NULL,
totalPlaces INTEGER NOT NULL
totalPlaces INTEGER NOT NULL,
validationDate Datetime
);
This diff is collapsed.
settings_custom.py
__pycache__/
.button-success,
.button-error,
.button-warning,
.button-secondary {
color: white;
border-radius: 4px;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.button-success {
background: rgb(28, 184, 65); /* this is a green */
}
.button-error {
background: rgb(202, 60, 60); /* this is a maroon */
}
.button-warning {
background: rgb(223, 117, 20); /* this is an orange */
}
.button-secondary {
background: rgb(66, 184, 221); /* this is a light blue */
}
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,16 +3,22 @@
# @Author: klmp200
# @Date: 2016-07-03 17:57:28
# @Last Modified by: klmp200
# @Last Modified time: 2016-11-05 18:49:18
# @Last Modified time: 2016-11-05 20:23:47
from bottle import Bottle, static_file, request, template, redirect
from bottle.ext import sqlite
import datetime
import settings
app = Bottle()
plugin = sqlite.Plugin(dbfile='../data/sqliteDB.db')
app.install(plugin)
def serialize_table(table):
"""
Convert a row in a list of dict
"""
obj = list()
dict_tmp = {}
for row in table:
......@@ -22,20 +28,39 @@ def serialize_table(table):
obj.append(dict_tmp)
return obj
@app.route('/app.apk')
@app.route('/gala.apk')
def GetApp():
return static_file("app.apk", root="../data/")
"""
Allow to download the gala
"""
return static_file("gala.apk", root="../data/")
@app.route('/scanner.apk')
def GetScan():
"""
Allow to download the qr code reader
"""
return static_file("scanner.apk", root="../data/")
@app.route('/')
def HomePage():
text = ''.join(("<h1>Serveur de validation de ebillets du gala</h1><p>Cliquez <a href=",
"/app.apk",">ici</a> pour télécarger l'application</p>"))
return text
"""
Home page
"""
return template('home.simple')
@app.route('/keys')
def GetKeys():
"""
Return json file for keys
"""
return static_file("keys.json", root="../data/")
@app.route('/delete/<db_id>')
def DeleteTicket(db, db_id=None):
"""
......@@ -62,38 +87,34 @@ def DisplayAdmin(db):
id where id the id in database
verifKey the verification key of the ticket
"""
table = []
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 form['ajax']:
return dict(data=tickets)
else:
form = ObtainGetArgs(request.query, ['id', 'verifKey'])
tickets = SearchDb(db, form)
return template('admin.simple', table=tickets, form=form)
@app.route('/admin/ajax', method='GET')
def DisplayAdminAjax(db):
"""
Get data from database same as DisplayAdmin
Return json for ajax request
"""
form = ObtainGetArgs(request.query, ['id', 'verifKey'])
tickets = SearchDb(db, form)
return dict(data=tickets)
def SearchDb(db, args):
"""
Qwery used in db
"""
if args['id'] or args['verifKey']:
table = db.execute("SELECT * from ticket where upper(verifKey) like :key or id =:id",
{"key": '%' + args['verifKey'] + '%',
{"key": '%' + args['verifKey'].upper() + '%',
"id": args['id']}).fetchall()
else:
table = db.execute('SELECT * from ticket').fetchall()
return table
tickets = serialize_table(table)[::-1]
return tickets
def ObtainGetArgs(query, args):
......@@ -129,6 +150,10 @@ def EditTicketQuantity(db, id_ticket, nb):
@app.route('/validate', method='POST')
def Validate(db):
"""
Verify in bdd if the ticket exists and create it
Return a json to the app
"""
try:
send = request.json
......@@ -147,19 +172,24 @@ def Validate(db):
def NewEntry(db, data):
"""
Add a new ticket in bdd
"""
available = data['nb'] - data['qt']
response = {
"available": available,
"valid": True
}
db.execute('INSERT into ticket(verifKey, availablePlaces, totalPlaces) values (?, ?, ?)',
(data['verif'], available, data['nb']))
db.execute('INSERT into ticket(verifKey, availablePlaces, totalPlaces, validationDate) values (?, ?, ?, ?)',
(data['verif'], available, data['nb'], datetime.datetime.now().strftime('%Hh %Mmin %Ss')))
return dict(response)
def UpdateEntry(db, data, obj):
"""
Update info in ticket
"""
availableP = obj['availablePlaces'] - data['qt']
if availableP >= 0:
......@@ -179,6 +209,6 @@ def UpdateEntry(db, data, obj):
return dict(response)
app.run(host='0.0.0.0', port=8080, debug=True)
app.run(host=settings.HOST, port=settings.PORT, debug=settings.DEBUG)
app.uninstall(plugin)
# -*- coding: utf-8 -*-
# @Author: klmp200
# @Date: 2016-11-05 19:58:43
# @Last Modified by: klmp200
# @Last Modified time: 2016-11-05 20:02:41
HOST = '0.0.0.0'
PORT = '8080'
DEBUG = True
# Loads custom settings
try:
from settings_custom import *
except:
print("Custom settings import failed")
......@@ -27,6 +27,7 @@
<th>Clef de vérification</th>
<th>Places restantes</th>
<th>Places total disponible</th>
<th>Heure d'ajout</th>
<th>Modifier quantité</th>
<th>Supprimer ticket</th>
</tr>
......@@ -37,6 +38,7 @@
<td>{{element['verifKey']}}</td>
<td>{{element['availablePlaces']}}</td>
<td>{{element['totalPlaces']}}</td>
<td>{{element['validationDate']}}</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>
......@@ -71,16 +73,16 @@
setInterval(function (){
var args = {
"id": getUrlParameter('id'),
"verifKey": getUrlParameter('verifKey'),
"ajax": 'l'
"verifKey": getUrlParameter('verifKey')
};
$.get("/admin", args).done(function(data){
$.get("/admin/ajax", args).done(function(data){
var to_write = "";
data['data'].forEach(function(ticket){
to_write += "<tr>";
to_write += "<td>" + ticket['verifKey'] + "</td>";
to_write += "<td>" + ticket['availablePlaces'] + "</td>";
to_write += "<td>" + ticket['totalPlaces'] + "</td>";
to_write += "<td>" + ticket['validationDate'] + "</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>";
......
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="/media/css/jquery-ui.min.css">
<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>
<body>
<div class="pure-g">
<div class="pure-u-1-24 pure-u-md-1-12 pure-u-sm-1-24"></div>
<div class="pure-u-22-24 pure-u-md-10-12 pure-u-sm-22-24">
<h1>Serveur de validation de ebillets du gala</h1>
<div id="accordion">
<h2>Section de téléchargement</h2>
<div>
<p>
Application de vérification : <a class="pure-button pure-button-primary" href="/gala.apk">Gala de prestige</a>
</p>
<p>
Application de scan : <a class="pure-button pure-button-primary" href="/scanner.apk">Barecode Reader</a>
</p>
</div>
<h2>Instructions d'installation</h2>
<div>
<p>Activez l'installation des applications de sources inconnues en allant dans paramètres -> sécurité -> sources inconnues (voir exemple suivant)</p>
<img src="/media/img/tuto1.png">
<img src="/media/img/tuto2.png">
<p>Téléchargez et installez l'application gala</p>
<p>Si aucun lecteur de qr code n'est installé, prenez celle fournie sur ce site</p>
</div>
<h3>Fonctionnement</h3>
<div>
Une fois que tout a été installé, il suffit de lancer l'application gala de prestige et y entrer les informations du serveur.
</div>
</div>
</div>
<div class="pure-u-1-24 pure-u-md-1-12 pure-u-sm-1-24"></div>
</div>
<footer>
<script type="text/javascript" src="/media/js/jquery.js"></script>
<script type="text/javascript" src="/media/js/jquery-ui.min.js"></script>
<script>
$( function() {
$( "#accordion" ).accordion({
heightStyle: "content"
});
} );
</script>
</footer>
</body>
</html>
\ No newline at end of file
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