Ei kuvausta

__init__.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. error = None
  25. if not cName:
  26. error = 'Name is required.'
  27. elif not cEmail:
  28. error = 'Email is required'
  29. else:
  30. db = get_db()
  31. station_id = db.execute(
  32. 'SELECT s_id FROM station WHERE nombre_empleado=?',
  33. (place_holder)
  34. ).fetchone()
  35. db.execute(
  36. 'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
  37. (station_id)
  38. )
  39. turn = db.execute(
  40. 'SELECT last_turn FROM station WHERE s_id=?',
  41. (station_id)
  42. )
  43. db.execute(
  44. 'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
  45. ' VALUES (?, ?, ?, ?)',
  46. (cName, cEmail, turn, 'testin', station_id)
  47. )
  48. db.commit()
  49. return app