from datetime import datetime 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'] db = get_db() station_query_res = db.execute( 'SELECT s_id FROM station WHERE nombre_empleado=?', (station_name,) ).fetchone() if station_query_res is not None: station_id = station_query_res[0] db.execute( 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?', (station_id,) ) turn_query_res = db.execute( 'SELECT last_turn FROM station WHERE s_id=?', (station_id,) ).fetchone() if turn_query_res is not None: turn = turn_query_res[0] db.execute( 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)' ' VALUES (?, ?, ?, ?, ?)', (cName, cEmail, turn, '{0:%H:%M}'.format(datetime.now()), station_id) ) db.commit() return redirect(url_for('index')) db = get_db() stations = db.execute( 'SELECT s_id, nombre_empleado, oficina FROM station' ' ORDER BY oficina ASC' ).fetchall() return render_template('index.html', stations=stations)