Example #1
0
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')
Example #2
0
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')
Example #3
0
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)
Example #4
0
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')
Example #5
0
File: shows.py Project: 51aps/Fyyer
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")