Geen omschrijving

index.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. db = get_db()
  14. station_query_res = db.execute(
  15. 'SELECT s_id FROM station WHERE nombre_empleado=?',
  16. (station_name,)
  17. ).fetchone()
  18. if station_query_res is not None:
  19. station_id = station_query_res[0]
  20. db.execute(
  21. 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
  22. (station_id,)
  23. )
  24. turn_query_res = db.execute(
  25. 'SELECT last_turn FROM station WHERE s_id=?',
  26. (station_id,)
  27. ).fetchone()
  28. if turn_query_res is not None:
  29. turn = turn_query_res[0]
  30. db.execute(
  31. 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
  32. ' VALUES (?, ?, ?, ?, ?)',
  33. (cName, cEmail, turn, 'testin', station_id)
  34. )
  35. db.commit()
  36. return redirect(url_for('index'))
  37. return render_template('index.html')