示例#1
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

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

    try:
        artist = db.session.get(Artist, artist_id)
        venue = db.session.get(Venue, venue_id)
        show = Show(start_time=start_time)
        show.artist = artist
        show.venue = venue
        db.session.add(show)
        db.session.commit()

        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except Exception as e:
        print(e)
        # DONE: on unsuccessful db insert, flash an error instead.
        # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/
        flash('An error occurred. Show could not be listed.')

    return render_template('pages/home.html')
示例#2
0
def create(show_record: ShowRecord,
           current_user: str = Depends(get_current_user)):
    """
    create a show record
    """

    try:
        show = Show()
        show.artist = show_record.artist
        show.venue = show_record.venue
        show.city = show_record.city
        show.date = show_record.date
        show.festival = show_record.festival
        show.creator_id = current_user.id

        db.add(show)
        db.commit()
    except sqlalchemy.exc.IntegrityError:
        return {
            "code": "error",
            "message": "User already exists with that username or email"
        }
    except Exception as e:
        print(e)

    return {"code": "SUCCESS"}
示例#3
0
def create_show_submission():
    # called to create new shows in the db, upon submitting new show listing form
    try:
        venue_id = request.form['venue_id']
        artist_id = request.form['artist_id']
        start_time = request.form['start_time']

        venue = Venue.query.filter_by(id=venue_id)[0]
        artist = Artist.query.filter_by(id=artist_id)[0]
        show = Show(venue_id=venue_id,
                    artist_id=artist_id,
                    start_time=start_time)

        show.venue = venue
        show.artist = artist

        db.session.add(venue)
        db.session.add(artist)
        db.session.commit()
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except SQLAlchemyError as e:
        db.session.rollback()
        flash(e)
    finally:
        db.session.close()
    return render_template('pages/home.html')
示例#4
0
文件: app.py 项目: fEyebrow/fyyur
def create_show_submission():
    error = False
    try:
        venue_id = request.form['venue_id']
        artist_id = request.form['artist_id']
        start_time = request.form['start_time']

        show = Show(venue_id=venue_id,
                    artist_id=artist_id,
                    start_time=start_time)
        venue = Venue.query.get(venue_id)
        artist = Artist.query.get(artist_id)
        show.venue = venue
        show.artist = artist
        db.session.add(show)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    if not error:
        # on successful db insert, flash success
        flash('Show was successfully listed!')
        return render_template('pages/home.html')
    else:
        flash('An error occurred. Show could not be listed.')
        abort(500)
示例#5
0
文件: app.py 项目: saadalmogren/FSND
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:
        venue_id = request.form.get('venue_id')
        artist_id = request.form.get('artist_id')
        start_time = request.form.get('start_time')
        busy_time = BusyTime.query.filter(artist_id == artist_id).filter(start_time > BusyTime.end_date and start_time < BusyTime.end_date)
        if busy_time is not None:
            raise (Exception)
            flash("The Artitst is busy at "+ start_time.strftime('%Y-%m-%d %H:%M:%S'))
        show = Show(venue_id=venue_id, artist_id=artist_id,
                    start_time=start_time)
        venue = Venue.query.get(venue_id)
        artist = Artist.query.get(artist_id)
        show.venue = venue
        show.artist = artist
        db.session.add(show)
        db.session.commit()
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except Exception:
        flash("The Artitst is busy at "+ start_time)
    except:
        db.session.rollback()
        print(sys.exc_info())
        # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Show could not be listed.')
    finally:
        db.session.close()

    return render_template('pages/home.html')
示例#6
0
文件: app.py 项目: DUCK251/fyyurapp
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)
示例#7
0
文件: app.py 项目: m16shoukry/FSND
def create_show_submission():
  form = request.form
  artist = Artist.query.get(form['artist_id'])
  venue = Venue.query.get(form['venue_id'])
  show = Show(start_time=form['start_time'])
  show.artist = artist
  show.venue = venue
  try:
    db.session.add(show)
    db.session.commit()  
    flash('Show was successfully listed!') 
  except:
    if (error=True):
    db.session.rollback
    flash('An error occurred. Show could not be listed.')
  finally:
    db.session.close()
  return render_template('pages/home.html')