|
@@ -6,39 +6,38 @@ from flask import (
|
6
|
6
|
from werkzeug.exceptions import abort
|
7
|
7
|
|
8
|
8
|
from app.db import get_db
|
|
9
|
+from app.forms import TurnForm
|
9
|
10
|
|
10
|
11
|
bp = Blueprint('index', __name__)
|
11
|
12
|
|
12
|
13
|
@bp.route('/', methods=('GET', 'POST'))
|
13
|
14
|
def index():
|
14
|
|
- if request.method == 'POST':
|
15
|
|
- cName = request.form['cName']
|
16
|
|
- cEmail = request.form['cEmail']
|
17
|
|
- station_name = request.form['station']
|
|
15
|
+ form = TurnForm()
|
|
16
|
+ if form.validate_on_submit():
|
|
17
|
+ station_id = request.form['station']
|
18
|
18
|
|
19
|
19
|
db = get_db()
|
20
|
|
- station_query_res = db.execute(
|
21
|
|
- 'SELECT s_id FROM station WHERE nombre_empleado=?',
|
22
|
|
- (station_name,)
|
23
|
|
- ).fetchone()
|
24
|
|
- if station_query_res is not None:
|
25
|
|
- station_id = station_query_res[0]
|
26
|
20
|
db.execute(
|
27
|
21
|
'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
|
28
|
22
|
(station_id,)
|
29
|
23
|
)
|
30
|
|
- turn_query_res = db.execute(
|
|
24
|
+ turn = db.execute(
|
31
|
25
|
'SELECT last_turn FROM station WHERE s_id=?',
|
32
|
26
|
(station_id,)
|
33
|
|
- ).fetchone()
|
34
|
|
- if turn_query_res is not None:
|
35
|
|
- turn = turn_query_res[0]
|
|
27
|
+ ).fetchone()[0]
|
36
|
28
|
db.execute(
|
37
|
29
|
'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
|
38
|
30
|
' VALUES (?, ?, ?, ?, ?)',
|
39
|
|
- (cName, cEmail, turn, '{0:%H:%M}'.format(datetime.now()), station_id)
|
|
31
|
+ (form.cName.data, form.cEmail.data, turn, '{0:%H:%M}'.format(datetime.now()), station_id)
|
40
|
32
|
)
|
|
33
|
+ station_info = db.execute(
|
|
34
|
+ 'SELECT nombre_empleado, oficina FROM station WHERE s_id=?',
|
|
35
|
+ (station_id,)
|
|
36
|
+ ).fetchone()
|
41
|
37
|
db.commit()
|
|
38
|
+
|
|
39
|
+ flash('Your turn for {} ({}) is number {}'.format(station_info['nombre_empleado'], station_info['oficina'], turn))
|
|
40
|
+
|
42
|
41
|
return redirect(url_for('index'))
|
43
|
42
|
|
44
|
43
|
db = get_db()
|
|
@@ -46,4 +45,4 @@ def index():
|
46
|
45
|
'SELECT s_id, nombre_empleado, oficina FROM station'
|
47
|
46
|
' ORDER BY oficina ASC'
|
48
|
47
|
).fetchall()
|
49
|
|
- return render_template('index.html', stations=stations)
|
|
48
|
+ return render_template('index.html', stations=stations, form=form)
|