No Description

__init__.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os
  2. from flask import Flask
  3. def create_app(test_config=None):
  4. app = Flask(__name__, instance_relative_config=True)
  5. app.config.from_mapping(
  6. SECRET_KEY='dev',
  7. DATABASE=os.path.join(app.instance_path, 'upr_espera.sqlite'),
  8. )
  9. if test_config is None:
  10. app.config.from_pyfile('config.py', silent=True)
  11. else:
  12. app.config.from_mapping(test_config)
  13. try:
  14. os.makedirs(app.instance_path)
  15. except OSError:
  16. pass
  17. from . import db
  18. db.init_app(app)
  19. @app.route('/', methods=('GET', 'POST'))
  20. def index():
  21. if request.method == 'POST':
  22. cName = request.form['cName']
  23. cEmail = request.form['cEmail']
  24. station_name = request.form['station']
  25. error = None
  26. if not cName:
  27. error = 'Name is required.'
  28. elif not cEmail:
  29. error = 'Email is required'
  30. else:
  31. db = get_db()
  32. station_id = db.execute(
  33. 'SELECT s_id FROM station WHERE nombre_empleado=?',
  34. (station_name,)
  35. ).fetchone()
  36. db.execute(
  37. 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
  38. (station_id,)
  39. )
  40. turn = db.execute(
  41. 'SELECT last_turn FROM station WHERE s_id=?',
  42. (station_id,)
  43. ).fetchone()
  44. db.execute(
  45. 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
  46. ' VALUES (?, ?, ?, ?)',
  47. (cName, cEmail, turn, 'testin', station_id)
  48. )
  49. db.commit()
  50. return app