def create_show_submission(): """ The function create new show with venue id,artist id and start time filled into Show Form and insert new show to database Returns: Render Home Page with flash for successed or faild """ Show_form = ShowForm(request.form) Valid_Artist_Id = Artist.query.get(Show_form.artist_id.data) Valid_Venue_Id = Venue.query.get(Show_form.venue_id.data) if(Valid_Venue_Id==None or Valid_Artist_Id==None): flash('Venue or Artist not found. Show could not be listed.') return render_template('pages/home.html') try: New_Show = Show() New_Show.venue_id = Show_form.venue_id.data New_Show.artist_id = Show_form.artist_id.data New_Show.start_time = Show_form.start_time.data db.session.add(New_Show) db.session.commit() flash('Show was successfully listed!') except: db.session.rollback() flash('An error occurred. Show could not be listed.') finally: db.session.close() return render_template('pages/home.html')
def create_show_submission(): error = False try: data = request.form show = Show() show.venue_id = data['venue_id'] show.artist_id = data['artist_id'] show.start_time = data['start_time'] db.session.add(show) db.session.commit() except: db.session.rollback() error = True print(sys.exc_info()) finally: db.session.close() if error: flash('ERROR: Show could not be listed!') else: flash('Show successfully listed!') return render_template('pages/home.html')
def create_show_submission(): # 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 try: # from form artist_id = request.form['artist_id'] venue_id = request.form['venue_id'] start_time = request.form['start_time'] # create a new show show = Show() show.venue_id = venue_id show.artist_id = artist_id show.start_time = start_time # add show to db db.session.add(show) db.session.commit() flash('Show was successfully listed!') # exception handler except: db.session.rollback() flash('An error occurred. Show could not be listed.') # close session finally: db.session.close() # 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(): # validate form form = ShowForm(request.form) if not form.validate(): return render_template('forms/new_show.html', form=form) # create show error = False try: show = Show() show.venue_id = request.form.get('venue_id', '') show.artist_id = request.form.get('artist_id', '') show.start_time = request.form.get('start_time', '') db.session.add(show) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash('Show could not be listed.') else: flash('Show was successfully listed!') return render_template('pages/home.html')
def addShowsData(): shows = Show.query.all() # only load data if db is empty if (not len(shows)): for defaultShow in shows_default_data: show = Show() show.venue_id = defaultShow['venue_id'] show.artist_id = defaultShow['artist_id'] show.start_time = defaultShow['start_time'] db.session.add(show) db.session.commit()
def create_show_submission(): # 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 error = False form = ShowForm(request.form) try: show = Show() form.populate_obj(show) db.session.add(show) db.session.commit() flash(' validate Thank You .') except ValueError as e: print(e) flash(' Error You input Invalidate Please Try again .') db.session.rollback() finally: db.session.close() new_show = Show() new_show.artist_id = request.form['artist_id'] new_show.venue_id = request.form['venue_id'] new_show.start_time = request.form['start_time'] now = datetime.now() new_show.upcoming = (now < dateutil.parser.parse(str(new_show.start_time))) try: db.session.add(new_show) updated_artist = Artist.query.get(new_show.artist_id) updated_venue = Venue.query.get(new_show.venue_id) if (new_show.upcoming): updated_artist.upcoming_shows_count += 1 updated_venue.upcoming_shows_count += 1 else: updated_artist.past_shows_count += 1 updated_venue.past_shows_count += 1 db.session.commit() except: error = True db.session.rollback() flash('Venues ID or Artist ID Not Found Please Cheack Again!', category='error') return render_template('pages/home.html') finally: db.session.close() if error: #TODO: on unsuccessful db insert, flash an error instead. flash('An error occurred. Shows could not be listed.') else: flash('Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm() if form.validate_on_submit(): try: show = Show() show.artist_id = form.artist_id.data.id show.venue_id = form.venue_id.data.id show.start_time = form.start_time.data db.session.add(show) db.session.commit() flash('Show was successfully listed!') except Exception as e: flash('An error occurred: ' + str(e)) db.session.rollback() finally: db.session.close() return redirect(url_for('shows')) return render_template('forms/new_show.html', form=form)
def create_show_submission(): form = ShowForm() if form.validate_on_submit(): try: show = Show() show.artist_id = request.form['artist_id'] show.venue_id = request.form['venue_id'] show.start_time = request.form['start_time'] db.session.add(show) db.session.commit() except Exception as e: db.session.rollback() flash('An error occurred. Show Could not be listed!, {}'.format( str(e))) finally: db.session.close() flash('Show was successfully listed!') return redirect(url_for('shows')) return render_template('forms/new_show.html', form=form)
def create_show_submission(): error = False try: show = Show() show.artist_id = request.form['artist_id'] show.venue_id = request.form['venue_id'] show.start_time = request.form['start_time'] db.session.add(show) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash('An error occurred. Requested show could not be listed.') else: flash('Requested show was successfully listed') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) # 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 # try: show = Show() show.venue_id = request.form['venue_id'] show.artist_id = request.form['artist_id'] show.start_time = request.form['start_time'] show.insert() # on successful db insert, flash success flash('Show was successfully listed!') # TODO: on unsuccessful db insert, flash an error instead. # except: #flash('An error occurred. Show could not be listed.') # 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(): # 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 - DONE # TODO: on unsuccessful db insert, flash an error instead. - DONE # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ 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() # on successful db insert, flash success flash('Show was successfully listed!') except: db.session.rollback() # on unsuccessful db insert, flash an error flash('An error occurred. Show could not be listed.') finally: return render_template('pages/home.html')
def create_show_submission(): errorFlag = False submission = request.form try: show = Show() show.venue_id = submission['venue_id'] show.artist_id = submission['artist_id'] show.start_time = submission['start_time'] db.session.add(show) db.session.commit() except Exception as e: errorFlag = True db.session.rollback() finally: db.session.close() if not errorFlag: # on successful db insert, flash success flash('Show was successfully listed!') else: flash('An error occurred. Show could not be listed.') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # TODO: [COMPLETED] insert form data as a new Show record in the db, instead error = False date_format = '%Y-%m-%d %H:%M:%S' try: show = Show() show.artist_id = request.form['artist_id'] show.venue_id = request.form['venue_id'] show.start_time = datetime.strptime(request.form['start_time'], date_format) db.session.add(show) db.session.commit() except Exception as e: error = True print(f'Error ==> {e}') db.session.rollback() finally: db.session.close() if error: flash('An error occurred. Show could not be listed.') else: flash('Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form data = Show() error = False # TODO: insert form data as a new Show record in the db, instead try: data.start_time = request.form['start_time'] data.artist_id = request.form['artist_id'] data.venue_id = request.form['venue_id'] db.session.add(data) db.session.commit() except: # TODO: on unsuccessful db insert, flash an error instead. error = True flash('An error occurred. This show could not be listed.') finally: # on successful db insert, flash success if error == False: flash('Show was successfully listed!') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) new_show = Show() new_show.artist_id = form.artist_id.data new_show.venue_id = form.venue_id.data dateAndTime = form.start_time.data new_show.start_time = form.start_time.data try: db.session.add(new_show) # on successful db insert, flash success db.session.commit() flash('Show was successfully listed!') except: db.session.rollback() # TODO: on unsuccessful db insert, flash an error instead. flash( 'Show could not be listed. please make sure that your ids are correct' ) finally: db.session.close() # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return render_template('pages/home.html')
def create_show_submission(): error = False try: show = Show() show.start_time = request.form['start_time'] show.venue_id = request.form['venue_id'] show.artist_id = request.form['artist_id'] db.session.add(show) db.session.commit() except Exception as e: error = True print(e) db.session.rollback() finally: db.session.close() if error: flash( 'An error occured. show starting at ' + request.form['start_time'] + ' Could not be listed.', 'error') else: flash('Show starting at' + request.form['start_time'] + ' was successfully listed!') return render_template('pages/home.html')