12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from flask import (
- Blueprint, flash, g, redirect, render_template, request, url_for
- )
- from werkzeug.exceptions import abort
-
- from app.db import get_db
-
- bp = Blueprint('index', __name__)
-
- @bp.route('/', methods=('GET', 'POST'))
- def index():
- if request.method == 'POST':
- cName = request.form['cName']
- cEmail = request.form['cEmail']
- station_name = request.form['station']
- error = None
-
- if not cName:
- error = 'Name is required.'
- elif not cEmail:
- error = 'Email is required'
- else:
- db = get_db()
- station_id = db.execute(
- 'SELECT s_id FROM station WHERE nombre_empleado=?',
- (station_name,)
- ).fetchone()
- db.execute(
- 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
- (station_id,)
- )
- turn = db.execute(
- 'SELECT last_turn FROM station WHERE s_id=?',
- (station_id,)
- ).fetchone()
- db.execute(
- 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
- ' VALUES (?, ?, ?, ?)',
- (cName, cEmail, turn, 'testin', station_id)
- )
- db.commit()
- return redirect(url_for('index.index'))
- return render_template('index.html')
|