def create_show_submission(): error = False try: artits_id = request.form.get('artist_id') venue_id = request.form.get('venue_id') start_time = request.form.get('start_time') show = Show() show.artist_id = artits_id show.venue_id = venue_id show.start_time = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") db.session.add(show) db.session.commit() except: error = True db.session.rollback() finally: db.session.close() # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead # on successful db insert, flash success if error == False: flash('Show was successfully listed!') else: flash('Show was failed listed!') # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return render_template('pages/home.html')
def create_show_submission(): try: show = Show() show.artist_id = request.form.get('artist_id') show.venue_id = request.form.get('venue_id') show.start_time = request.form.get('start_time') db.session.add(show) db.session.commit() flash('Show was successfully created!') except: print(sys.exc_info()) db.session.rollback() flash('An error occurred. Show could not be created.') finally: db.session.close() return render_template('pages/home.html')