def create_show_submission(): """ function for creating shows, that will create new 'show' object in the DB and add it then commit """ # 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) err = False try: date_format = '%Y-%m-%d %H:%M:%S' show = Shows() 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() # 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/ except: err = True db.session.rollback() finally: db.session.close() if err: flash('ERROR. The entered show has not been listed.') else: flash('Show was successfully listed!') # on successful db insert, flash success return render_template("pages/home.html")
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form newShow = Shows(artist_id=request.form['artist_id'], venue_id=request.form['venue_id'], show_date=request.form['start_time']) if Shows.insert(newShow): flash('Show was successfully listed!') return redirect(url_for('shows')) else: flash('An error occurred. Show could not be listed.') abort(404) return render_template('pages/home.html')
def create_show_submission(): """ Creates a new show in the Shows database Returns: on POST: Redirects to the home page after the new show has been added to the database. """ # 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 form = ShowForm(request.form) try: new_show = Shows(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) db.session.add(new_show) db.session.commit() # on successful db insert, flash success flash('Show was successfully listed!') # TODO: on unsuccessful db insert, flash an error instead. except Exception as e: flash('An error occurred. Show could not be listed.') db.session.rollback() finally: db.session.close() return render_template('pages/home.html')
def create_show_submission(): try: venue_id = request.form['venue_id'] artist_id = request.form['artist_id'] artist = Artist.query.get(artist_id) venue = Venue.query.get(venue_id) if not venue or not artist: errors = { artist: "invalid artist", venue: "invalid venue", } return redirect(url_for('create_shows', errors=errors)) date = request.form['start_time'] show = Shows(venue_id=venue_id, artist_id=artist_id, date=date) db.session.add(show) db.session.commit() flash('Show was successfully listed!') except: flash('An error occurred. Show could not be listed.') db.session.rollback() finally: db.session.close() 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 form = ShowForm() try: artist_id = db.session.query(Artist).filter_by(id = request.form.get("artist_id")).first() venue_id = db.session.query(Venue).filter_by(id = request.form.get("venue_id")).first() if artist_id is not None or venue_id is not None: create_show = Shows( artist_id = request.form.get("artist_id"), venue_id = request.form.get("venue_id"), start_time = request.form.get("start_time") ) db.session.add(create_show) db.session.commit() # on successful db insert, flash success flash('Show was successfully listed!') else: flash('Check if artist Id or Venue Id is right!') except Exception as error: flash('An error occurred. Show could not be 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(): # called to create new shows in the db, upon submitting new show listing form # TODO: OK | insert form data as a new Show record in the db, instead show_form = ShowForm(request.form) try: # Create a new instance of Show with data from ShowForm show = Shows.insert().values( Artist_id=show_form.artist_id.data, Venue_id=show_form.venue_id.data, start_time=show_form.start_time.data ) db.session.execute(show) db.session.commit() # on successful db insert, flash success flash('Show was successfully listed!') except : # TODO OK: on unsuccessful db insert, flash an error instead. flash('An error occurred. Show could not be listed.','error') db.session.rollback() print(sys.exc_info()) finally: db.session.close() # 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: data = request.form form = ShowForm(data, csrf_enabled=False) if form.validate(): aid = data['artist_id'] vid = data['venue_id'] checka = Artist.query.get(aid) checkb = Venue.query.get(vid) if (checka and checkb): sho = Shows(Artist_id=data['artist_id'], Venue_id=data['venue_id'], start_time=data['start_time']) db.session.add(sho) db.session.commit() flash('show ' + data['artist_id'] + data['venue_id'] + data['start_time'] + ' was successfully listed!') db.session.close() return redirect(url_for('index')) else: flash('the ids should be valied') return redirect(url_for('create_shows')) else: flash(form.errors) return redirect(url_for('create_shows')) except: flash('An error occurred. the new show could not be listed.') return render_template('errors/500.html')
def create_show_submission(): error=False try: artist_id = request.form.get('artist_id', '') venue_id = request.form.get('venue_id', '') start_time = request.form.get('start_time', '') shows = Shows( artist_id=artist_id, venue_id=venue_id, start_time=start_time ) db.session.add(shows) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) 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') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form error = False try: form = ShowForm(request.form, meta={'csrf': False}) newshow = Shows() form.populate_obj(newshow) # print(newshow) db.session.add(newshow) db.session.commit() except: db.session.rollback() print(sys.exc_info()) error = True finally: db.session.close() if error: flash('An error occurred. Show could not be listed.') print('error listed!') return render_template('pages/home.html') else: print('Show was successfully listed!') flash('Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) form.artist_id.choices = [(artist.id, artist.name) for artist in Artist.query.all()] form.venue_id.choices = [(venue.id, venue.name) for venue in Venue.query.all()] if not form.validate(): return render_template("forms/new_show.html", form=form) try: artist_id = form.artist_id.data venue_id = form.venue_id.data start_time = form.start_time.data show_is_exists = Shows.query.filter_by( artist_id=artist_id, venue_id=venue_id ).all() if show_is_exists: flash("This show already exists") return render_template("forms/new_show.html", form=form) show = Shows(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() flash("Show was successfully listed!") except Exception as e: print(e) db.session.rollback() flash("An error occurred.") finally: db.session.close() return render_template("pages/home.html")
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # DONE: insert form data as a new Show record in the db, instead error = False try: show = Shows(artist_id=request.form['artist_id'], venue_id=request.form['venue_id'], start_time=request.form['start_time']) db.session.add(show) db.session.commit() except: error = True db.session.rollback() flash('An error occurred. Show could not be listed') finally: db.session.close() if not error: flash('Show was successfully listed!') # on successful db insert, flash success # DONE: 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(): form = ShowForm(request.form) if form.validate_on_submit(): error = False try: show = Shows(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) show.insert() except Exception: error = True db.session.rollback() print(exc_info()) finally: db.session.close() flash("An error occurred. Show could not be listed")\ if error else flash('Show was successfully listed!') return render_template('pages/home.html') else: flash('Please ensure all details provided are valid') return render_template('forms/new_show.html', form=form)
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 show_form = ShowForm(request.form) try: new_show = Shows.insert().values(venue_id=show_form.venue_id.data, artist_id=show_form.artist_id.data, date=show_form.start_time.data) db.session.execute(new_show) db.session.commit() flash('Show was successfully listed!') except: db.session.rollback() print(sys.exc_info()) flash('An error occurred. ') return render_template('pages/home.html')
def create_show_submission(): try: artist_id = request.form['artist_id'] venue_id = request.form['venue_id'] start_time = request.form['start_time'] show = Shows(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() flash('Show was successfully listed!') except: flash('An error occurred. Show could not be listed.') db.session.rollback() print(sys.exc_info) finally: db.session.close() return render_template('pages/home.html')
def create_shows_submission(): error = False try: show = Shows(artist_id=request.form['artist_id'], venue_id=request.form['venue_id'], start_time=show.start_time.strftime("%m/%d/%Y, %H:%M")) db.session.add(show) db.session.commit() flash('Successfully added a new show!') print('I am in show area 2s end ') except: db.session.rollback() flash('Error. Could not list new show') error = True print('I am in show area 3') finally: db.session.close() print('I am in show area 4') return render_template('pages/home.html')
def create_show_submission(): try: artist_id = request.form.get('artist_id') venue_id = request.form.get('venue_id') start_time = request.form.get('start_time') new_show = Shows(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(new_show) db.session.commit() flash('Show was successfully listed!') except Exception as e: print(e) db.session.rollback() flash('An error occured posting a new show') print(sys.exc_info()) finally: db.session.close return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # Done: insert form data as a new Show record in the db, instead try: form = ShowForm(request.form) show = Shows() form.populate_obj(show) db.session.add(show) db.session.commit() # on successful db insert, flash success flash('Show was successfully listed!') except Exception: db.session.rollback() # Done: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Venue ' + data.name + ' could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ flash('An error occurred. Show could not be listed.') print(sys.exc_info()) finally: db.session.close() return render_template('pages/home.html')
def create_show_submission(): #DONE error = False try: form = ShowForm(request.form) print(form) show_list = Shows(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) db.session.add(show_list) db.session.commit() flash('New show was successfully listed!') except Exception as e: print(e) error = True db.session.rollback() flash('An error occurred. New show could not be listed.') finally: db.session.close() 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: s = Shows(datetime=request.form.get('start_time'), artistId=request.form.get('artist_id'), venueId=request.form.get('venue_id')) db.session.add(s) db.session.commit() flash('Show was successfully listed!') except Exception as e: print(e) flash('An error occurred. Show could not be listed.') db.session.rollback() finally: db.session.close() # on successful db insert, flash success # 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(): form = ShowForm(request.form, csrf_enabled=False) if form.validate(): try: show = Shows() form.populate_obj(show) db.session.add(show) db.session.commit() flash('Show was successfully listed!') except ValueError as e: print(e) flash('Show listing was unsuccessful!') db.session.rollback() finally: db.session.close() else: message = [] for field, err in form.errors.items(): message.append(field + ' ' + '|'.join(err)) flash('Errors ' + str(message)) 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) show_form = ShowForm() artist_id = show_form.artist_id.data venue_id = show_form.venue_id.data start_time = show_form.start_time.data show = Shows.insert().values(artist_id=artist_id, venue_id=venue_id, start_time=start_time) try: db.session.execute(show) db.session.commit() # on successful db insert, flash success flash("Show was successfully listed!") except Exception as e: flash("An error occurred. Show could not be listed.") db.session.rollback() db.session.flush() print(e) 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 form = ShowForm(request.form) show = Shows(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) try: # on successful db insert, flash success db.session.add(show) db.session.commit() flash('Show to be held in ' + request.form['start_time'] + ' is successfully listed!') except: # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Artist ' + data.name + ' could not be listed.') db.session.rollback() flash('Error! Show could not be listed.') finally: db.session.close() return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # collect the information from the form start_time = request.form['start_time'] venue_id = request.form['venue_id'] artist_id = request.form['artist_id'] # data = [] error = False # TODO: insert form data as a new Show record in the db, instead try: # assign the information for a new show record new_show = Shows(start_time=start_time, venue_id=venue_id, artist_id=artist_id) # print(new_show) # inject information to the db db.session.add(new_show) db.session.commit() # retrieve back the information # created_show_id = new_show.id # data['start_time'] = new_show.start_time # data['venue_id'] = new_show.venue_id # data['artist_id'] = new_show.artist_id except: error = True # TODO: on unsuccessful db insert, flash an error instead. flash('An error occurred. Show could not be listed.') db.session.rollback() finally: db.session.close() if error: abort(400) else: # on successful db insert, flash success flash('Show was successfully listed!') # return jsonify(data) return redirect(url_for('index'))
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form data_recd_imm = request.form # print(data_recd_imm) just_fetch = Shows.query.first( ) # if we skip this then id is None & error occurs show_ins = Shows() # Instance of class for i in data_recd_imm: setattr(show_ins, i, data_recd_imm[i]) show_ins.start_time = datetime.strptime(show_ins.start_time, '%Y-%m-%d %H:%M:%S') show_date = show_ins.start_time.date() show_time = show_ins.start_time.time() reqArtist = Artist.query.filter_by(id=show_ins.artist_id).first() timingNotSuitable = False # Default state if ((reqArtist.artist_time_begin) and (show_time < reqArtist.artist_time_begin)): # Check begin time timingNotSuitable = True if ((reqArtist.artist_time_end) and (show_time > reqArtist.artist_time_end)): # Check end time timingNotSuitable = True if ((reqArtist.artist_date_begin) and (show_date < reqArtist.artist_date_begin)): # Check begin time timingNotSuitable = True if ((reqArtist.artist_date_end) and (show_date > reqArtist.artist_date_end)): # Check end time timingNotSuitable = True if (timingNotSuitable): flash('Available date for artist is ' + reqArtist.artist_date_begin.strftime('%Y-%m-%d') + ' to ' + reqArtist.artist_date_end.strftime('%Y-%m-%d') + ' between ' + reqArtist.artist_time_begin.strftime('%H:%M:%S') + ' to ' + reqArtist.artist_time_end.strftime('%H:%M:%S')) return redirect(url_for('create_shows')) error = False try: db.session.add(show_ins) # Insert in DB db.session.commit() except: db.session.rollback() error = True 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')
newEntries.append(newData) db.session.add_all(newEntries) db.session.commit() db.session.close() if Artist.query.count() == 0: print("Adding the data") for data in artistData: db.session.add(Artist(**data)) db.session.commit() db.session.close() if Shows.query.count() == 0: print("Adding show data!") for data in showData: db.session.add(Shows(**data)) db.session.commit() db.session.close() print("Data All Set!") #----------------------------------------------------------------------------# # Filters. #----------------------------------------------------------------------------# def format_datetime(value, format='medium'): date = dateutil.parser.parse(value) if format == 'full': format = "EEEE MMMM, d, y 'at' h:mma" elif format == 'medium': format = "EE MM, dd, y h:mma"