Esempio n. 1
0
def create_show_submission():
  # called to create new shows in the db, upon submitting new show listing form

  error = False
  try:
    form = ShowForm()
    show = Show(
      artist_id=form.artist_id.data,
      venue_id=form.venue_id.data,
      start_time=form.start_time.data
    )
    show.insert()

    #venue =  Venue.query.get(show.venue_id)
    #venue.upcoming_shows_count += 1
    #venue.update()

    #artist = Artist.query.get(show.artist_id)
    #artist.upcoming_shows_count += 1
    #artist.update()

  except:
    error = True
    print(sys.exc_info())
    db.session.rollback()

  if error:
    abort (400)
    flash('An error occured')
  else:
    flash('Show was successfully listed')
  # on successful db insert, flash success
  return render_template('pages/home.html')
Esempio n. 2
0
def create_show_submission():
    try:
        new_show = Show(venue_id=request.form['venue_id'],
                        artist_id=request.form['artist_id'],
                        start_time=request.form['start_time'])
        Show.insert(new_show)
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except SQLAlchemyError as e:
        flash('An error occurred. Show could not be listed.')
    return render_template('pages/home.html')
Esempio n. 3
0
def create_show_submission():
    form = ShowForm(request.form)
    try:
        show = Show(artist_id=form.artist_id.data,
                    venue_id=form.venue_id.data,
                    start_time=form.start_time.data)
        show.insert()
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except Exception as e:
        flash('An error occurred. Show could not be listed.')

    return render_template('pages/home.html')
Esempio n. 4
0
def create_show_submission():
    form = ShowForm()
    data = request.form

    try:
        new_show = Show(venue_id=data.get('venue_id'),
                        artist_id=data.get('artist_id'),
                        start_time=data.get('start_time'))
        Show.insert(new_show)
        flash('Show was successfuly listed!')
    except SQLAlchemyError as e:
        flash('An error occured. Show could not be listed.')

    return render_template('pages/home.html')
Esempio n. 5
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
    try:
        new_show = Show(venue_id=request.form['venue_id'],
                        artist_id=request.form['artist_id'],
                        date_time=request.form['start_time'])
        Show.insert(new_show)
        flash('Show was successfully listed!')
    except:
        flash('An error occurred. Show could not be listed.')
    # 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')
Esempio n. 6
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
    form = ShowForm(request.form)
    if form.validate():
        try:
            newShow = Show.insert().values(
                venue_id=request.form['venue_id'],
                artist_id=request.form['artist_id'],
                start_time=request.form['start_time'])
            db.session.execute(newShow)
            db.session.commit()
            # 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/
        finally:
            db.session.close()
    else:
        flash(form.errors)
        flash(
            'An error occurred due to form validation. Show could not be listed.'
        )
    return render_template('pages/home.html')
Esempio n. 7
0
def create_show_submission():
  # called to create new shows in the db, upon submitting new show listing form
  # TODO DONE: insert form data as a new Show record in the db, instead
  form = ShowForm(request.form)
  flashType = 'danger'
  if form.validate():
    # NOTE: Form could not be validated due to a missing csrf-token.
    # I solved this issue by putting a "{{ form.csrf_token() }}"
    # under the respective <form> tag in forms/new_show.html
    try:
      # Create a new instance of Show with data from ShowForm
      newShow = Show.insert().values(
        Venue_id = request.form['venue_id'],
        Artist_id = request.form['artist_id'],
        start_time = request.form['start_time']
      )
      db.session.execute(newShow)
      db.session.commit()
      # on successful db insert, flash success
      flashType = 'success'
      flash('Show was successfully listed!')
    except :
      # TODO: on unsuccessful db insert, flash an error instead.
      flash('An error occurred due to database insertion error. Show could not be listed.')
    finally:
      # Always close session
      db.session.close()
  else:
    flash(form.errors) # Flashes reason, why form is unsuccessful (not really pretty)
    flash('An error occurred due to form validation. Show could not be listed.')

  return render_template('pages/home.html', flashType = flashType)
Esempio n. 8
0
def create_show_submission():
    # TODO: insert form data as a new Show record in the db, instead
    try:
        new_show = Show(
            venue_id=request.form['venue_id'],
            artist_id=request.form['artist_id'],
            start_time=request.form['start_time'],
        )
        Show.insert(new_show)

        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except SQLAlchemyError as e:
        # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occured. Show could not be listed.')
    return render_template('pages/home.html')
Esempio n. 9
0
def create_show_submission():
    # called to create new shows in the db, upon submitting new show listing form
    try:
        new_show = Show(
            venue_id=request.form['venue_id'],
            artist_id=request.form['artist_id'],
            start_time=request.form['start_time'],
        )
        Show.insert(new_show)

        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except SQLAlchemyError as e:
        # on unsuccessful db insert, flash an error instead.
        flash('An error occured. Show could not be listed.')
    return render_template('pages/home.html')
Esempio n. 10
0
def create_show_submission():
    try:
        form = ShowForm(request.form)

        show = Show(
            venue_id=form.venue_id.data,
            artist_id=form.artist_id.data,
            start_time=form.start_time.data,
        )
        show.insert()

        flash('Show was successfully listed!')
    except Exception as e:
        flash('An error occurred. Show could not be listed.')
        print('Error', e)
    finally:
        return render_template('pages/home.html')
def create_show_submission():
    try:
        show = Show(venue_id=request.form.get('venue_id'),
                    artist_id=request.form.get('artist_id'),
                    start_time=request.form.get('start_time'))
        show.insert()
        flash('Show was successfully listed!')
    except:
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
        # TODO: modify data to be the data object returned from db insertion

    # on successful db insert, flash success
    # TODO: on unsuccessful db insert, flash an error instead.
    # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/
    finally:
        db.session.close()
        return render_template('pages/home.html')
Esempio n. 12
0
    def post_show(jwt):
        """Create a show route"""
        # Process request data
        data = request.get_json()
        show_name = data.get('show_name', None)
        show_date = data.get('show_date', None)

        # return 400 for empty show_name or show date
        if show_name is None or show_date is None:
            abort(400)

        show = Show(show_name=show_name, show_date=show_date)

        try:
            show.insert()
            return jsonify({'success': True, 'show': show.format()}), 200
        except BaseException:
            abort(404)
Esempio n. 13
0
def create_show_submission():
  form = ShowForm()

  try:
    show = Show(
      venue_id=form.venue_id.data,
      artist_id=form.artist_id.data,
      start_time=form.start_time.data
    )
    show.insert()
    flash('Show was successfully listed!', 'success')
  except:
    db.session.rollback()
    flash('An error occurred. Show could not be listed.', 'error')
  finally:
    db.session.close()

  return render_template('pages/home.html')
Esempio n. 14
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
    try:
        show = Show(
            artist_id=request.form['artist_id'],
            venue_id=request.form['venue_id'],
            start_time=request.form['start_time'],
        )
        show.insert()
        flash('Show was successfully listed!')
    except:
        rollback()
        flash('An error occurred. Show could not be listed.')
    finally:
        close()

    return render_template('pages/home.html')
Esempio n. 15
0
 def create_show_submission():
     # called to create new shows in the db, upon submitting new show listing form
     # inserts form data as a new Show record in the db
     form = ShowForm()
     try:
         show = Show(
             venue_id=form.venue_id.data,
             artist_id=form.artist_id.data,
             start_time=form.start_time.data,
         )
         show.insert()
         flash('Show was successfully listed!')
     except:
         show.rollback()
         flash('An error occurred. Show could not be listed.')
     finally:
         show.close()
     return render_template('pages/home.html')
Esempio n. 16
0
 def create_show_using_form(cls, form):
     try:
         new_show = Show.insert().values(venue_id=form['venue_id'],
                                         artist_id=form['artist_id'],
                                         start_time=form['start_time'])
         db.session.execute(new_show)
         db.session.commit()
     except Exception as e:
         print(e)
         db.session.close()
         raise ValueError('This for is in valid')
Esempio n. 17
0
def create_show_submission():
    '''Create new Show

  Input: None

  Contains following features:
    - Called upon submitting the new Show listing form
    - Handle data from ShowForm
    - Create new Show with given data
    - Handle success & error with declerative flashes & messages

  Corresponding HTML:
      - templates/pages/new_artist.html

  '''

    # TODO DONE: insert form data as a new Show record in the db, instead

    form = ShowForm(
        request.form)  # Initialize form instance with values from the request
    flashType = 'danger'  # Initialize flashType to danger. Either it will be changed to "success" on successfully db insert, or in all other cases it should be equal to "danger"
    if form.validate():
        # NOTE: Form could not be validated due to a missing csrf-token.
        # I solved this issue by putting a "{{ form.csrf_token() }}"
        # under the respective <form> tag in forms/new_show.html
        try:
            # Create a new instance of Show with data from ShowForm
            newShow = Show.insert().values(
                Venue_id=request.form['venue_id'],
                Artist_id=request.form['artist_id'],
                start_time=request.form['start_time'])
            db.session.execute(newShow)
            db.session.commit()
            # on successful db insert, flash success
            flashType = 'success'
            flash('Show was successfully listed!')
        except:
            # TODO DONE: on unsuccessful db insert, flash an error instead.
            flash(
                'An error occurred due to database insertion error. Show could not be listed.'
            )
        finally:
            # Always close session
            db.session.close()
    else:
        flash(form.errors
              )  # Flashes reason, why form is unsuccessful (not really pretty)
        flash(
            'An error occurred due to form validation. Show could not be listed.'
        )

    return render_template('pages/home.html', flashType=flashType)
Esempio n. 18
0
    def add_show(payload):
        try:
            body = request.get_json()
            show_data = {
                'movie_id': body['movie_id'],
                'actors_ids': body['actors_ids']
            }
            # check if a show with this movie already exists
            check_movie = Show.query.filter(
                Show.movie_id == show_data['movie_id']).all()
            if check_movie:  # if check_movie has a movie
                abort(400)
            no_of_actors = len(show_data['actors_ids'])
            for actor in range(no_of_actors):
                new_show = Show(movie_id=show_data['movie_id'],
                                actor_id=show_data['actors_ids'][actor])
                new_show.insert()

            shows = list_shows()

            return jsonify({'success': True, 'shows': shows})
        except:
            abort(422)
Esempio n. 19
0
def create_show_submission():

    error = False

    artist_id = request.form.get('artist_id')
    venue_id = request.form.get('venue_id')
    start_time = request.form.get('start_time')

    print(venue_id, artist_id, start_time)

    try:
        s = Show(venue_id, artist_id, start_time)
        s.insert()

    except:
        error = True
        db.session.rollback()

    if error:
        flash('An error occurred. Show could not be listed.')
    else:
        flash('Show was successfully listed!')

    return render_template('pages/home.html')
Esempio n. 20
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
    try:
        data_in = request.form
        show_sql = Show.insert().values(artist_id=data_in['artist_id'],
                                        venue_id=data_in['venue_id'],
                                        start_time=data_in['start_time'])
        db.engine.execute(show_sql)
        flash('Show was successfully listed!')
    except:
        flash('An error occurred. Show could not be listed.')

# 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/
    artists = db.session.query(Artist).order_by(
        Artist.datecreate.desc()).limit(10)
    venues = db.session.query(Venue).order_by(
        Venue.datecreate.desc()).limit(10)

    return render_template('pages/home.html', artists=artists, venues=venues)