def create_venue_submission(): error = False try: venue = Venue() venue.name = request.form['name'] venue.city = request.form['city'] venue.state = request.form['state'] venue.address = request.form['address'] venue.phone = request.form['phone'] genre = request.form.getlist('genres') venue.genres = ','.join(genre) venue.facebook_link = request.form['facebook_link'] db.session.add(venue) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) db.session.close() if error: flash('An error occured. Venue ' + request.form['name']) else: flash('Venue ' + request.form['name'] + ' was successfully added!') return render_template('pages/home.html')
def create_venue_submission(): # TODO: insert form data as a new Venue record in the db, instead # TODO: modify data to be the data object returned from db insertion error = False try: data = Venue() data.name = request.form['name'] data.city = request.form['city'] data.state = request.form['state'] data.address = request.form['address'] data.phone = request.form['phone'] data.genres = request.form.getlist('genres') data.facebook_link = request.form['facebook_link'] if Venue.query.filter_by(name=data.name).filter_by( city=data.city).filter_by(state=data.state).filter_by( address=data.address) != None: flash("Venue " + request.form['name'] + " is already in the database") return render_template('pages/home.html') db.session.add(data) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash("error occurs at " + request.form['name']) print(sys.exc_info()) if not error: # on successful db insert, flash success flash('Venue ' + request.form['name'] + ' was successfully listed!') # TODO: 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/ return render_template('pages/home.html')