|
@@ -0,0 +1,43 @@
|
|
1
|
+from flask import (
|
|
2
|
+ Blueprint, flash, g, redirect, render_template, request, url_for
|
|
3
|
+)
|
|
4
|
+from werkzeug.exceptions import abort
|
|
5
|
+
|
|
6
|
+from app.db import get_db
|
|
7
|
+
|
|
8
|
+bp = Blueprint('index', __name__)
|
|
9
|
+
|
|
10
|
+@bp.route('/', methods=('GET', 'POST'))
|
|
11
|
+def index():
|
|
12
|
+ if request.method == 'POST':
|
|
13
|
+ cName = request.form['cName']
|
|
14
|
+ cEmail = request.form['cEmail']
|
|
15
|
+ station_name = request.form['station']
|
|
16
|
+ error = None
|
|
17
|
+
|
|
18
|
+ if not cName:
|
|
19
|
+ error = 'Name is required.'
|
|
20
|
+ elif not cEmail:
|
|
21
|
+ error = 'Email is required'
|
|
22
|
+ else:
|
|
23
|
+ db = get_db()
|
|
24
|
+ station_id = db.execute(
|
|
25
|
+ 'SELECT s_id FROM station WHERE nombre_empleado=?',
|
|
26
|
+ (station_name,)
|
|
27
|
+ ).fetchone()
|
|
28
|
+ db.execute(
|
|
29
|
+ 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
|
|
30
|
+ (station_id,)
|
|
31
|
+ )
|
|
32
|
+ turn = db.execute(
|
|
33
|
+ 'SELECT last_turn FROM station WHERE s_id=?',
|
|
34
|
+ (station_id,)
|
|
35
|
+ ).fetchone()
|
|
36
|
+ db.execute(
|
|
37
|
+ 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
|
|
38
|
+ ' VALUES (?, ?, ?, ?)',
|
|
39
|
+ (cName, cEmail, turn, 'testin', station_id)
|
|
40
|
+ )
|
|
41
|
+ db.commit()
|
|
42
|
+ return redirect(url_for('index.index'))
|
|
43
|
+ return render_template('index.html')
|