示例#1
0
文件: app.py 项目: JanaAleid55/Fyyur
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')
示例#2
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
    error = False
    try:
        Show(venue_id=request.form['venue_id'],
             artist_id=request.form['artist_id'],
             start_time=request.form['start_time'])
    except:
        error = True
        flash('An error occurred. Show could not be listed.')
        db.session.rollback()
    finally:
        if not error:
            db.session.commit()
            flash('Show was successfully listed!')
            db.session.close()
    return render_template('pages/home.html')
示例#3
0
文件: app.py 项目: trendysloth/fyyur
def create_show_submission():
    # called to create new shows in the db, upon submitting new show listing
    # form
    try:
        form = ShowForm()
        show = Show(venue_id=form.venue_id.data,
                    artist_id=form.artist_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 as e:
        flash(f'An error occurred. Show could not be listed. Error: {e}')
        db.session.rollback()
        return render_template('forms/new_show.html', form=form)
    finally:
        db.session.close()
示例#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
    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.
        # 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('pages/home.html')
示例#5
0
文件: app.py 项目: neelxie/fyyur-
def create_show_submission():
  form = ShowForm()
  artist_id = db.session.query(Artist).filter_by(id = request.form.get("artist_id")).first()
  venue_id = db.session.query(Venue).filter_by(id = request.form.get("venue_id")).first()

  if (artist_id is None) or (venue_id is None):
    flash('Either Artist ID or Venue ID doesnt exist')
  new_show = Show(venue_id=request.form.get("venue_id"), artist_id=request.form.get("artist_id"))
  db.session.add(new_show)
  db.session.commit()


  # on successful db insert, flash success
  flash('Show was successfully listed!')
  # 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')
示例#6
0
文件: app.py 项目: Marvinsky/fyyur
def create_show_submission():
    new_show = ShowForm()

    try:
        new_show = Show(artist_id=new_show.artist_id.data,
                        venue_id=new_show.venue_id.data,
                        start_time=new_show.start_time.data)
        db.session.add(new_show)
        db.session.commit()
        flash('Show was successfully listed!')
    except:
        flash('An error occurred. Show could not be listed.')
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()

    return render_template('pages/home.html')
示例#7
0
    def test_show_attrs(self):
        with gillard.app.app_context():
            show = Show('TESTID', 'TESTPW')
            show.title = 'A TEST SHOW TITLE'
            show.startDay = 2
            show.startHour = 4
            show.endDay = 6
            show.endHour = 8

            show = test_utils.save_and_refresh(gillard.db.session, show)

            assert show.display_id == 'TESTID'
            assert show.password == 'TESTPW'
            assert show.title == 'A TEST SHOW TITLE'
            assert show.startDay == 2
            assert show.startHour == 4
            assert show.endDay == 6
            assert show.endHour == 8
示例#8
0
文件: app.py 项目: misbahsy/capstone
    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)
示例#9
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)
示例#10
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')
示例#11
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')
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')
示例#13
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()
    if form.validate_on_submit():
        newShow = Show(
            artist_id=form.artist_id.data,
            venue_id=form.venue_id.data,
            start_time=form.start_time.data,
        )
        db.session.add(newShow)
        db.session.commit()
        flash('Show was successfully listed!')
    else:
        flash('An error occurred. Show could not be listed.', 'error')
        flash(form.errors)

    return render_template('pages/home.html')
示例#14
0
def create_show_submission():
    artist_id = request.form['artist_id']
    venue_id = request.form['venue_id']
    start_time = request.form['start_time']
    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!')
    except Exception:
        flash('An error occurred. Show could not be listed.')
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    return render_template('pages/home.html')
示例#15
0
def webhook_sonarr():
    try:
        if request.json['eventType'] == 'Test':
            aprint('Received TEST webhook', 'WEBHOOK.MAIN')
            return HTTPResponse(status=200)
        if not request.json:
            error = {
                'error': 'Request JSON not correct',
                'code': 10,
            }
            return HTTPResponse(status=500, body=error)
        webhook_request = request.json
        episodes = webhook_request['episodes']
    except:
        error = {
            'error': 'Request JSON not correct',
            'code': 10,
        }
        return HTTPResponse(status=500, body=error)

    for episode in episodes:
        episode_data = {
            'SERIES': webhook_request['series']['title'],
            'SEASON': str(episode['seasonNumber']).zfill(2),
            'EPISODE': str(episode['episodeNumber']).zfill(2),
            'TITLE': episode['title'],
            'QUALITY': episode.get('quality', 'Unknown')
        }

        msg = '{SERIES} - {SEASON}x{EPISODE} - {TITLE} | {QUALITY}'.format(
            SERIES=episode_data['SERIES'],
            SEASON=episode_data['SEASON'],
            EPISODE=episode_data['EPISODE'],
            TITLE=episode_data['TITLE'],
            QUALITY=episode_data['QUALITY'])
        new_show = Show(series=episode_data['SERIES'],
                        season=episode_data['SEASON'],
                        episode=episode_data['EPISODE'],
                        title=episode_data['TITLE'],
                        quality=episode_data['QUALITY'],
                        timestamp=datetime.datetime.now(current_tz))
        new_show.save()
        aprint(msg, 'WEBHOOK.TV')
    return HTTPResponse(status=200)
示例#16
0
def create_show_submission():
    error = False
    try:
        show = Show(artist_id=request.form.get('artist_id'),
                    venue_id=request.form.get('venue_id'),
                    start_time=request.form.get('start_time'))
        db.session.add(show)
        db.session.commit()
        # on successful db insert, flash success
        flash('Show was successfully listed!')
    except:
        error = True
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
    finally:
        db.session.close()
    if not error:
        redirect(url_for('shows'))
    return render_template('pages/home.html')
示例#17
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
        )
        db.session.add(show)
        db.session.commit()
        flash('Show was successfully listed!')

    except ValueError as e:
        print(e)
        db.session.rollback()
        flash(f'An error occurred.  Show could not be listed.')
    finally:
        db.session.close()
    return render_template('pages/home.html')
示例#18
0
def create_show_submission():
    form = ShowForm(request.form)

    try:
        new_show = Show(artist_id=form.artist_id.data,
                        venue_id=form.venue_id.data,
                        start_time=form.start_time.data)
        db.session.add(new_show)
        db.session.commit()

        flash('Show was successfully listed!')
    except:
        db.session.rollback()
        flash('Error: Show could not be added!')
        traceback.print_exc()
    finally:
        db.session.close()

    return render_template('pages/home.html')
示例#19
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)
示例#20
0
def create_show_submission():

    form = ShowForm(request.form, meta={'csrf': False})
    if form.validate():
        try:
            date_time_obj = form.start_time.data
            #Query to help to find out if there are shows in the same day and hour
            artist_shows = db.session.query(Show).join(Artist).filter(
                and_(Show.artist_id == form.artist_id.data,
                     func.DATE(Show.start_time) == date_time_obj.date(),
                     extract('hour',
                             Show.start_time) == date_time_obj.hour)).first()
            #if there are not results, the show would be added correctly
            if (artist_shows == None):
                show = Show(artist_id=form.artist_id.data,
                            venue_id=form.venue_id.data,
                            start_time=date_time_obj)
                db.session.add(show)
                db.session.commit()
                flash('Show was successfully listed!')
            else:
                flash(
                    'The artist has already booked an event at the same time and hour'
                )
        except ValueError as e:
            print(e)
            error = True
            db.session.rollback()
            #if there are a mistake, a message would be displayed
            flash('The Show could not be listed.')
            not_found_error(400)

        finally:
            print('final')
            db.session.close()

    else:
        message = []
        for field, err in form.errors.items():
            message.append(field + ' ' + '|'.join(err))
        flash('Errors ' + str(message))

    return render_template('pages/home.html')
示例#21
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
    error = False

    venue_id = request.form.get('venue_id')
    venue_row = Venue.query.get(venue_id)
    venue_name = venue_row.name

    artist_id = request.form.get('artist_id')
    artist_row = Artist.query.get(artist_id)
    artist_name = artist_row.name

    if not (venue_row is None or artist_row is None):
        try:
            # create new Show object with recived values
            new_show_row = Show(artist_id=artist_id,
                                venue_id=venue_id,
                                start_time=request.form.get('start_time'))
            db.session.add(new_show_row)
            db.session.commit()
        except:
            db.session.rollback()
            error = True
            print(sys.exc_info())
        finally:
            db.session.close()

        if error:
            # on unsuccessful db insert, flash an error instead.
            flash('An error occurred. Show ' + artist_name + ' playing at ' +
                  venue_name + ' at ' + request.form.get('start_time') +
                  ' could not be listed.')
        else:
            # on successful db insert, flash success
            flash('Show ' + artist_name + ' playing at ' + venue_name +
                  ' at ' + request.form.get('start_time') +
                  ' was successfully listed!')

    else:
        flash('Venue id or Artist id not found ')

    return redirect(url_for('shows'))
示例#22
0
def create_show_submission():
    req = request.form
    show = Show(start_date=datetime.strptime(req['start_time'],
                                             '%Y-%m-%d %H:%M:%S'),
                venue_id=int(req['venue_id']),
                artist_id=int(req['artist_id']))

    try:
        db.session.add(show)
        db.session.commit()
    except:
        db.session.rollback()
        flash('An error occurred. Show could not be listed.')
        return render_template('pages/home.html')
    finally:
        db.session.close()
    flash('Show was successfully listed!')

    return render_template('pages/home.html')
示例#23
0
文件: app.py 项目: ljmccode/Fyyur
def create_show_submission():
    error=False
    data=request.form

    try:
        new_show=Show(
            artist_id=data.get('artist_id'),
            venue_id=data.get('venue_id'),
            start_time=data.get('start_time')
        )
        db.session.add(new_show)
        db.session.commit()
        # on successful db insert, flash success
        flash("New show was successfully listed!")
    except():
        db.session.rollback()
        error=True
        flash('An error occurred. New show could not be listed.')
    return render_template('pages/home.html')
示例#24
0
def create_show_submission():
    form = ShowForm(csrf_enabled=True)
    artist = Artist.query.filter_by(id=form.artist_id.data).first()
    venue = Venue.query.filter_by(id=form.venue_id.data).first()
    if not artist:
        flash(
            "The Artist does not exist yet. Please first create or choose another artist"
        )
        return render_template('pages/home.html')
    elif artist.seeking_venue is False:
        flash("The Artists you selected is not seeking a venue")
        return render_template('pages/home.html')
    elif not venue:
        flash(
            "The Venue selected does not exist yet. Please first create it or choose another venue"
        )
        return render_template('pages/home.html')
    if form.validate_on_submit():
        show_data = dict(name=form.name.data,
                         artist_id=form.artist_id.data,
                         artist_image_link=artist.image_link,
                         artist_name=artist.name,
                         venue_id=form.venue_id.data,
                         venue_name=venue.name,
                         start_time=form.start_time.data,
                         end_time=form.end_time.data,
                         date=form.date.data,
                         show_fee=form.fee.data)
        check_show_exists = Show.query.filter_by(
            name=form.name.data, venue_id=form.venue_id.data).first()
        if check_show_exists:
            flash(
                'The Show you are trying to create already exists. Please create another one'
            )
            return render_template('pages/home.html')
        new_show = Show(**show_data)
        new_show.save()
        flash('Show ' + request.form['name'] + ' was successfully added!')
    else:
        errors = form.errors
        for key, error in errors.items():
            flash(f'{key}  Error ' + " => " + f"{error[0]}")
    return render_template('pages/home.html')
示例#25
0
def create_show_submission() -> str:
    form_data = request.form.to_dict()
    try:
        venue = Venue.query.filter_by(id=form_data["venue_id"]).one()
    except exc.NoResultFound:
        raise exc.NoResultFound(
            f"No venue id = {form_data['venue_id']} was found].")

    try:
        artist = Artist.query.filter_by(id=form_data["artist_id"]).one()
    except exc.NoResultFound:
        raise exc.NoResultFound(
            f"No artist id = {form_data['artist_id']} was found.'")

    data = {
        "venue_id":
        venue.id,
        "venue_name":
        venue.name,
        "venue_image_link":
        venue.image_link,
        "artist_id":
        artist.id,
        "artist_name":
        artist.name,
        "artist_image_link":
        artist.image_link,
        "start_time": (parser.parse(
            form_data["start_time"]).strftime("%Y-%m-%dT%H:%M:%S.%fZ")),
    }

    show = Show(**data)

    try:
        db.session.add(show)
        db.session.commit()
        flash("Show was successfully listed!")
    except SQLAlchemyError:
        db.session.rollback()
        flash("An error occurred. Show could not be listed.")

    return render_template("pages/home.html")
示例#26
0
文件: app.py 项目: carevon/fyyur
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
    error = False
    form = ShowForm()
    show_id = db.session.query(db.func.max(Show.id)).scalar()
    try:
        if form.validate_on_submit():
            id = show_id + 1
            venue_id = request.form['venue_id']
            artist_id = request.form['artist_id']
            start_time = request.form['start_time']

            show = Show(id=id,
                        venue_id=venue_id,
                        artist_id=artist_id,
                        start_time=start_time,
                        created_at=datetime.now(timezone(timedelta(hours=-3))),
                        updated_at=datetime.now(timezone(timedelta(hours=-3))))

            db.session.add(show)
            db.session.commit()
        else:
            for e in form.errors:
                flash('An error has occurred. {}'.format(form.errors[e]))
            db.session.rollback()
            return render_template('pages/shows.html')
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()

    # DONE: on unsuccessful db insert, flash an error instead.
    if error:
        flash('An error has occurred. Show could not be listed.')
    else:  # on successful db insert, flash success
        flash('Show was successfully listed!')
    # 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')
示例#27
0
def create_show_submission():
    form = ShowForm()
    # surface form field validation errors
    if not form.validate():
        flash("Please correct the following errors: " + str(form.errors))
        if "start_time" in form.errors:
            flash("Please format start time as YYYY:MM:DD HH:MM")
        flash('Show could not be listed.')
        return render_template('forms/new_show.html', form=form)
    else:
        # try and look up IDs, collect any errors, surface them jointly
        error = False
        try:
            artist = Artist.query.get(form.data["artist_id"])
            assert len(artist.name) > 0
        except:
            error = True
            flash("Please provide a valid Artist ID.")
        try:
            venue = Venue.query.get(form.data["venue_id"])
            assert len(venue.name) > 0
        except:
            error = True
            flash("Please provide a valid Venue ID.")
        if error == True:
            flash('Show could not be listed.')
            return render_template('forms/new_show.html', form=form)
        else:
            # try and write show to DB
            try:
                show = Show(venue_id=form.data["venue_id"],
                            artist_id=form.data["artist_id"],
                            time=form.data["start_time"])
                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.')
            finally:
                db.session.close()
            return render_template('pages/home.html')
示例#28
0
文件: app.py 项目: kbakande/fyyur
 def create_show_submission():
     form = ShowForm()
     if form.validate_on_submit():
         error = False
         try:
             artistid = Artist.query.filter_by(
                 id=request.form['artist_id']).scalar()
             venueid = Venue.query.filter_by(
                 id=request.form['venue_id']).scalar()
             if not venueid:
                 pass
             elif not artistid:
                 pass
             else:
                 show = Show(artist_id=request.form['artist_id'],
                             venue_id=request.form['venue_id'],
                             start_time=request.form['start_time'])
                 db.session.add(show)
                 db.session.commit()
         except:
             error = True
             db.session.rollback()
             print(sys.exc_info())
         finally:
             if not venueid:
                 flash('Venue with ID ' + request.form['venue_id'] +
                       ' does not exist.')
                 return render_template('forms/new_show.html', form=form)
             elif not artistid:
                 flash('Artist with ID ' + request.form['artist_id'] +
                       ' does not exist.')
                 return render_template('forms/new_show.html', form=form)
             elif error:
                 db.session.close()
                 flash('Show was not successfully listed!')
                 return render_template('forms/new_show.html', form=form)
             else:
                 flash('Show was successfully listed!')
                 return render_template('pages/home.html')
     else:
         flash_errors(form)
         return render_template('forms/new_show.html', form=form)
示例#29
0
def create_show_submission():
    error = False
    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:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
        if error:
            flash('An error occurred. Requested show could not be listed.')
        else:
            flash('Requested show was successfully listed')
        return render_template('pages/home.html')
示例#30
0
def create_show_submission():
    error = False
    try:
        show = Show(artist_id=request.form['artist_id'],
                    venue_id=request.form['venue_id'],
                    start_time=request.form['start_time'])
        db.session.add(show)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
    finally:
        db.session.close()
    if not error:
        flash('Show was successfully listed!')
        return render_template('pages/home.html')
    else:
        form = ShowForm()
        flash('An error occurred. Show could not be listed.')
        return render_template('forms/new_show.html', form=form)