No Description

admin_insert.py 788B

123456789101112131415161718192021222324252627
  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. from app.forms import StationForm
  7. bp = Blueprint('admin_insert', __name__)
  8. @bp.route('/admin_insert', methods=('GET', 'POST'))
  9. def admin_insert():
  10. form = StationForm()
  11. if form.validate_on_submit():
  12. db = get_db()
  13. db.execute(
  14. 'INSERT INTO station (nombre_empleado, oficina, last_turn)'
  15. ' VALUES (?, ?, ?)',
  16. (form.eName.data, form.office.data, 0)
  17. )
  18. db.commit()
  19. flash('Added station for {} ({})'.format(form.eName.data, form.office.data))
  20. return redirect(url_for('admin_insert'))
  21. return render_template('admin_insert.html', form=form)