Sin descripción

index.py 1.3KB

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