Exemplo n.º 1
0
def create_show_submission():
    form = ShowForm(request.form, meta={'csrf': False})

    if form.validate_on_submit():
        error = False
        print(form.artist_id.data.artistId())
        try:
            show = Show(artist_id=form.artist_id.data.artistId(),
                        ven_id=form.venue_id.data.venId(),
                        start_time=form.start_time.data)

            db.session.add(show)
            db.session.commit()
        except BaseException as ee:
            print(ee)
            db.session.rollback()
            error = True
        finally:
            db.session.close()
            if error:
                flash('Error  While Insert')
            else:
                flash('Show  was successfully listed!')
    else:
        flash('Error ' + 'Missing Some Input')
    return render_template('pages/home.html')
Exemplo n.º 2
0
def create_show_submission():
    error = False
    form = ShowForm()
    try:
        if form.validate_on_submit():
            v_id = int(form.venue_id.data)
            show = Show(date_time=form.start_time.data, venue_id=v_id)
            db.session.add(show)
            db.session.commit()
            artist = Artist.query.get(form.artist_id.data)
            venue = Venue.query.get(v_id)
            show.artists.append(artist)
            venue.shows.append(show)
            db.session.add(venue)
            db.session.commit()
            flash('Show was successfully listed on {}!'.format(
                form.start_time.data))
            return redirect(url_for('index'))
        flash('An error occurred. Show could not be listed. {}'.format(
            form.errors))
    except ():
        db.session.rollback()
        error = True
        print(sys.exc_info())
    finally:
        db.session.close()
    if error:
        abort(500)
        flash('There was an error, please try again.')

    return render_template('pages/home.html')
Exemplo n.º 3
0
def create_show_submission():
    form = ShowForm()
    error = False
    try:
        if form.validate_on_submit():
            show = Show(start_time=form.start_time.data,
                        venue_id=form.venue_id.data,
                        artist_id=form.artist_id.data)
            db.session.add(show)
            db.session.commit()
    except Exception as e:
        print('create_show_submission: ', e)
        db.session.rollback()
        print(sys.exc_info())
        error = True
    finally:

        db.session.close()
    if error:

        flash('Oh!, an error occurred. Show could not be listed.')
        return render_template('forms/new_show.html', form=form)
    else:
        flash('Yaaay, Show was successfully listed!')
        return render_template('pages/home.html')
Exemplo n.º 4
0
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')
Exemplo 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
    form = ShowForm(request.form)
    try:
        form.validate()

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

        db.session.add(show)
        db.session.commit()
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except Exception as e:
        print(e)
        # 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/
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
    finally:
        db.session.close()

    return render_template('pages/home.html')
Exemplo n.º 6
0
def create_show_submission():
    error = False
    form = ShowForm(request.form)
    if not form.validate_on_submit():
        flash('An error occurred. Show could not be listed.')
        return render_template('pages/home.html')
    # noinspection PyBroadException
    try:
        artist_id = request.form['artist_id']
        venue_id = request.form['venue_id']
        start_time = request.form['start_time']
        show = Show(artist_id=artist_id,
                    venue_id=venue_id,
                    start_time=start_time)
        db.session.add(show)
        db.session.commit()
    except Exception:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    if error:
        flash('An error occurred. Show could not be listed.')
    if not error:
        flash('Show was successfully listed')
    return render_template('pages/home.html')
Exemplo n.º 7
0
def create_show_submission():
    # called to create new shows in the db, upon submitting new show listing form
    # insert form data as a new Show record in the db, instead
    # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/

    form = ShowForm(request.form, meta={"csrf": False})

    if form.validate_on_submit():
        try:
            show: Show = Show()
            form.populate_obj(show)
            db.session.add(show)
            db.session.commit()
            # on successful db insert, flash success
            flash(f"Show {request.form['name']} was successfully listed!")
        except ValueError as e:
            print(sys.exc_info())
            db.session.rollback()
            # on unsuccessful db insert, flash an error instead.
            flash(f"An error occurred: {str(e)}")
        finally:
            db.session.close()

    else:
        error_msg = []
        for field, error in form.errors.items():
            error_msg.append(f"{field}: {str(error)}")
        flash(f"Error occurred: {str(error_msg)}")

    return render_template('pages/home.html')
Exemplo n.º 8
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()
    created = False

    if form.validate_on_submit():
        try:
            new_show = Show(start_time=form.start_time.data)
            new_show.venue = form.venue.data
            new_show.artist = form.artist.data
            db.session.add(new_show)
            db.session.commit()
            # on successful db insert, flash success
            created = True
            flash("Show was successfully listed!")

        except:
            print(sys.exc_info())
        finally:
            db.session.close()

        if created:
            return redirect(url_for("index"))

    # TODO: on unsuccessful db insert, flash an error instead.
    flash("An error occurred. Show could not be listed.")
    return render_template("forms/new_show.html", form=form)
Exemplo n.º 9
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
  # 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/

  form = ShowForm(request.form, meta = {'csrf': False})

  if form.validate():
    try:
      show = Show()
      form.populate_obj(show)
      db.session.add(show)
      db.session.commit()
      flash('Show was successfully listed!')
    except ValueError as e:
      print(e)
      flash('Error in listing show. Please try again.')
      db.session.rollback()
    finally:
      db.session.close()
  else:
    err_msg = []
    for field, err in form.errors.items():
      err_msg.append(field + '-' + '|'.join(err))
    flash('Errors: ' + str(err_msg))

  return render_template('pages/home.html')
Exemplo n.º 10
0
def create_show_submission():
    form = ShowForm()
    error = False
    try:
        if form.validate_on_submit():
            show = Show(
                artist_id=form.artist_id.data,
                venue_id=form.venue_id.data,
                start_time=form.start_time.data
            )
            db.session.add(show)
            db.session.commit()
    except Exception as e:
        print('create_show_submission: ', e)
        db.session.rollback()
        print(sys.exc_info())
        error = True
    finally:
        db.session.close()
        # on successful db insert, flash success
    if error:
        # 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/
        flash('An error occurred. Show could not be listed.')
        return render_template('forms/new_show.html', form=form)
    else:
        flash('Show was successfully listed!')
        return render_template('pages/home.html')
Exemplo n.º 11
0
def create_show_submission():
    """Creates a new show in the db from a form submission.

    Returns:
        A redirect to the shows page
    """
    form = ShowForm()
    if not form.validate():
        flash(
            list(form.errors.values())[0][0],
            "error",
        )
        return redirect(url_for("create_show_form"))

    error = False

    try:

        venue_id = request.form.get("venue_id")
        artist_id = request.form.get("artist_id")
        start_time = request.form.get("start_time")
        unavailabilities = Unavailability.query.filter_by(
            artist_id=artist_id).all()

        for unavailability in unavailabilities:
            if (str(unavailability.start_time) > start_time < str(
                    unavailability.end_time)):
                flash("Artist is unavailable at selected time")
                return redirect(url_for("create_show_form"))

        show = Show(venue_id=venue_id,
                    artist_id=artist_id,
                    start_time=start_time)
        db.session.add(show)
        db.session.commit()

    except Exception:  # pylint: disable=broad-except
        error = True
        db.session.rollback()
        print(sys.exc_info())

    finally:
        db.session.close()

    if error:
        flash("Show was unable to be listed!", "error")
        abort(500)

    flash("Show was successfully listed!")

    return redirect(url_for("shows"))
Exemplo n.º 12
0
def create_show_submission():
  """
  Received POSTed form data for a new show and saves those details in the database
  Returns user to index.html
  """
  # 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()
  if form.validate():
    artist_id = form.artist_id.data
    venue_id = form.venue_id.data
    start_time = form.start_time.data

    # Isolate hour from desired show time
    start_time_only = str(start_time).split(' ')[1]
    start_time_hour = int(start_time_only[0] + start_time_only[1])

    # Get start and end hours for artist availability
    artist = Artist.query.get(artist_id)
    available_from = 0
    available_to = 23
    available_hours = artist.available_hours
    if available_hours:
      available_from = int(available_hours.split('-')[0])
      available_to = int(available_hours.split('-')[1])

    # If show time falls in Artist available hours, or no available hours were specified for the artist, try to list the show
    if (start_time_hour >= available_from) and (start_time_hour <= available_to):
      try: 
        show = Show(artist_id=artist_id, venue_id=venue_id, start_time=start_time)
        db.session.add(show)
        db.session.commit()
        flash('Show was successfully listed!')
        # 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
      except Exception as e:
        db.session.rollback()
        flash('ERROR: Show not created!')
      finally:
        db.session.close()  
    else:
      flash("Artist not avaiable at that time")

  # 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 redirect(url_for('index'))
Exemplo n.º 13
0
def show_venue(venue_id):
    # get by id
    venue = Venue.query.get(venue_id)

    # venue data
    data = venue.get_data()

    # show to dict
    def get_show_dict(show):
        return {
            "artist_id": show.artist.id,
            "artist_name": show.artist.name,
            "artist_image_link": show.artist.image_link,
            "start_time": show.start_time.strftime("%Y-%m-%d %H:%M:%S")
        }

    # past_shows
    past_shows = venue.get_past_shows()
    data['past_shows_count'] = len(past_shows)
    data['past_shows'] = []
    for show in past_shows:
        data['past_shows'].append(get_show_dict(show))

    # upcoming shows
    upcoming_shows = venue.get_upcoming_shows()
    data['upcoming_shows_count'] = len(upcoming_shows)
    data['upcoming_shows'] = []
    for show in upcoming_shows:
        data['upcoming_shows'].append(get_show_dict(show))

    showForm = ShowForm()
    return render_template('pages/show_venue.html',
                           venue=data,
                           showForm=showForm)
Exemplo n.º 14
0
def create_show_submission():
  # called to create new shows in the db, upon submitting new show listing form
  error = False
  data = {}
  form = ShowForm()
  # if form.validate_on_submit():
  try:
    artist_id = request.form['artist_id']
    venue_id = request.form['venue_id']
    start_time = request.form['start_time']
    # TODO: insert form data as a new Show record in the db, instead
    show = Show(
      artist_id=artist_id, 
      venue_id=venue_id, 
      start_time=start_time)
    db.session.add(show)
    db.session.commit()
    # TODO: modify data to be the data object returned from db insertion
    data['artist_id'] = show.artist_id
    data['venue_id'] = show.venue_id
    data['start_time'] = show.start_time
  except:
    db.session.rollback()
    print(sys.exc_info())
    error = True
  finally:
    db.session.close()
  # on successful db insert, flash success
  if error == False:
    flash('Show was successfully listed!')
    return render_template('pages/home.html')
  # TODO: on unsuccessful db insert, flash an error instead.
  else:
    flash('An error occurred. Show could not be listed.','error')
    return render_template('forms/new_show.html', form=form)
Exemplo n.º 15
0
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
    form = ShowForm()
    error = False

    artist_id = form.artist_id.data
    venue_id = form.venue_id.data
    start_time = form.start_time.data
    print(venue_id)

    try:
        show = Show(start_time=start_time,
                    artist_id=artist_id,
                    venue_id=venue_id)
        db.session.add(show)
        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.')
    else:
        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')
Exemplo n.º 16
0
def create_shows():
    data = {
        'venue_id': request.args.get('venue_id', ''),
        'artist_id': request.args.get('artist_id', '')
    }
    form = ShowForm(data=data)
    return render_template('forms/new_show.html', form=form)
Exemplo n.º 17
0
def create_shows():
    # renders form. do not touch.
    artist_choices = db.session.query(
        Artist.id, Artist.name).distinct().all()
    venue_choices = db.session.query(Venue.id, Venue.name).distinct().all()
    form = ShowForm(artist_choices, venue_choices)
    return render_template('forms/new_show.html', form=form)
Exemplo n.º 18
0
def create_show_submission():
    show_data = ShowForm(request.form)

    error = False
    try:
        # Create new db Show record
        new_show = Show(
            artist_id=show_data.artist_id.data,
            venue_id=show_data.venue_id.data,
            start_time=show_data.start_time.data
        )

        db.session.add(new_show)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        if not error:
            flash("Show was successfully listed!")
        else:
            flash("An error occurred. Show could not be listed.")
        db.session.close()

    return redirect(url_for('index'))
Exemplo n.º 19
0
def create_show_submission():
    form = ShowForm(request.form)
    error = False
    print("About to go into Show creation")
    try:
        print("Instantiating Show")
        data = Show(
            name=form.name.data,
            venue_id=form.venue_id.data,
            artist_id=form.artist_id.data,
            start_time=form.start_time.data
        )
        print("Adding to database")
        db.session.add(data)
        print("Committing data")
        db.session.commit()
        print("Persisted data")
    # TODO: modify data to be the data object returned from db insertion
        flash('Show ' + request.form['name'] + ' was successfully listed!')
    except Exception as e:
        print(("Rolling back transaction"))
        print(e)
        print(e.args)
        error = True
        db.session.rollback()
    # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Show ' +
              data.name + ' could not be listed.')
        return render_template('pages/home.html')
        print(sys.exc_info())
    finally:
        print("Closing session")
        db.session.close()
        return render_template('pages/home.html')
Exemplo n.º 20
0
Arquivo: app.py Projeto: madmed88/FSND
def create_show_submission():
    form = ShowForm(request.form)
    try:
        show = Show()
        form.populate_obj(show)
        db.session.add(show)
        db.session.commit()
        flash('Show was successfully listed!')

    except:
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
        raise
    finally:
        db.session.close()
    return render_template('pages/home.html')
Exemplo n.º 21
0
def create_show_submission():
    try:
        show = Show()
        form = ShowForm(request.form)
        show = populateObjectFromForm(show, form)
        if (show.end_time == None):
            print("Info: No end time submitted - adding default")
            show.end_time = show.start_time + default_booking_slot_duration
            print("end time: ", show.end_time)
        if not isShowWithinArtistAvailibility(show):
            raise ArtistUnavailable
        db.session.add(show)
        db.session.commit()
        flash('Show was successfully listed!')
    except ArtistUnavailable:
        db.session.rollback()
        flash(
            'An error occurred. Artist is not available during requested booking slot. Show could not be listed.'
        )
    except:
        print(sys.exc_info())
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
    finally:
        db.session.close()
    return redirect(url_for('index'))
Exemplo n.º 22
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

    # on successful db insert, flash success
    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()
        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)
        # 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():
    """ Submit callback for show form """
    # Get the form data
    artist_id = request.form['artist_id']
    venue_id = request.form['venue_id']
    start_time = request.form['start_time']

    form = ShowForm()
    # Validate form data
    if not form.validate_on_submit():
        flash(form.errors)
        # Redirect to the new_show.html page with the error message in the above line
        return redirect(url_for('create_show_submission'))

    error = False
    venue = Venue.query.get(venue_id)
    artist = Artist.query.get(artist_id)

    # Check if the venue id exists or not.
    if venue is None:
        flash('The venue id ' + venue_id + ' does not exist')
        return redirect(url_for('create_show_submission'))

    # Check if the artist id exists or not.
    if artist is None:
        flash('The artist id ' + artist_id + ' does not exist')
        return redirect(url_for('create_show_submission'))

    try:
        # Create Show instance using form data
        show = Show(venue_id=venue_id,
                    artist_id=artist_id,
                    start_time=start_time)
        db.session.add(show)
        db.session.commit()
    except():
        db.session.rollback()
        error = True
    finally:
        db.session.close()

    if error:
        flash(f'An error occurred. Show could not be listed')
        abort(500)
    else:
        flash(f'Show listed successfully')
        return render_template('pages/home.html')
Exemplo n.º 24
0
def create_show_form():
    """Displays the form for creating a show.

    Returns:
        A html template for the show form
    """
    form = ShowForm()
    return render_template("forms/new_show.html", form=form)
Exemplo n.º 25
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
    # 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/
    error = False
    form = ShowForm()
    try:
        if form.validate_on_submit():
            new_show = Show(start_time=form.start_time.data)
            venue = Venue.query.get(form.venue_id.data)
            artist = Artist.query.get(form.artist_id.data)
            if venue is None or artist is None:
                flash('Check Id')
                return render_template('forms/new_show.html', form=form)
            new_show.venue = venue
            new_show.artist = artist
            venue.shows.append(new_show)
            artist.shows.append(new_show)
            db.session.add(new_show)
            db.session.commit()
        else:
            error = True
            for fieldName, errorMessages in form.errors.items():
                for err in errorMessages:
                    print(err, file=sys.stdout)
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    # on successful db insert, flash success
    if (error):
        flash('Error!')
        return render_template('forms/new_show.html', form=form)
    else:
        flash('Show was successfully listed!')
        return redirect(url_for('index'))
    # 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('forms/new_show.html', form=form)
Exemplo n.º 26
0
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)
Exemplo n.º 27
0
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)
Exemplo n.º 28
0
def create_show_submission():
    form = ShowForm()
    if not form.validate_on_submit():
        flash(f'An error occurred. Show could not be listed.', 'error')
        return render_template('pages/home.html')

    try:
        new_show = Show.from_dict(form.data)
        print(new_show.id)
        db.session.add(new_show)
        db.session.commit()
        flash('Show was successfully listed!')
    except Exception as e:
        print(e)
        flash('An error occurred. Show could not be listed.')
    finally:
        db.session.close()

    return render_template('pages/home.html')
Exemplo n.º 29
0
def create_show_submission():
    form = ShowForm()
    if form.validate_on_submit():
        try:
            show = Show(artist_id=form.artist_id.data,
                        venue_id=form.venue_id.data,
                        start_time=form.start_time.data)
            db.session.add(show)
            db.session.commit()
            flash('Show was successfully listed!')
            return render_template('pages/home.html')
        except Exception:
            db.session.rollback()
            print(sys.exc_info())
            flash('An error occurred. Show could not be listed.')
            return render_template('pages/home.html')
        finally:
            db.session.close()
    else:
        return render_template('forms/new_show.html', form=form)
Exemplo n.º 30
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)