No Description

index.py 1.5KB

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