示例#1
0
def create_artist_submission():
    """ The function create new artist with properties filled into Artist Form
        and insert new artist to database   

    Returns:
       Render Home Page with flash for successed or faild   
    """
    New_Artist_Form = ArtistForm(request.form)
    try:
        New_Artist = Artist()
        New_Artist.name = New_Artist_Form.name.data
        New_Artist.genres = ','.join(New_Artist_Form.genres.data)
        New_Artist.city = New_Artist_Form.city.data
        New_Artist.state = New_Artist_Form.state.data
        New_Artist.phone = New_Artist_Form.phone.data
        New_Artist.facebook_link = New_Artist_Form.facebook_link.data
        if(not ValidPhoneNumber(New_Artist_Form.phone.data)):
            raise ValueError
        db.session.add(New_Artist)
        db.session.commit()
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    except ValueError:
        db.session.rollback()
        flash('Incorrect phone number format xxx-xxx-xxxx   (' + request.form['phone']+ '),  please try again.')
    except:
        db.session.rollback()
        flash('An error occurred. Artist ' + request.form['name'] + ' could not be listed.')
    finally:
        db.session.close()
    return render_template('pages/home.html')
示例#2
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    artist = Artist()
    artist.name = request.form.get('name')
    artist.city = request.form.get('city')
    artist.state = request.form.get('state')
    artist.phone = request.form.get('phone')
    artist.image_link = request.form.get('image_link')
    artist.facebook_link = request.form.get('facebook_link')
    artist.genres = request.form.getlist('genres')
    try:
        db.session.add(artist)
        db.session.commit()
    except:
        db.session.rollback()
    finally:
        db.session.close()
    # TODO: modify data to be the data object returned from db insertion

    # on successful db insert, flash success
    flash('Artist ' + request.form['name'] + ' was successfully listed!')
    # TODO: on unsuccessful db insert, flash an error instead.
    # e.g., flash('An error occurred. Artist ' + data.name + ' could not be listed.')
    return render_template('pages/home.html')
示例#3
0
def create_artist_submission():
    form = ArtistForm()
    error = False
    try:
        artist = Artist()
        artist.name = request.form['name']
        artist.city = request.form['city']
        artist.state = request.form['state']
        artist.phone = request.form['phone']
        tmp_genres = request.form.getlist('genres')
        artist.genres = ','.join(tmp_genres)
        artist.website = request.form['website']
        artist.image_link = request.form['image_link']
        artist.facebook_link = request.form['facebook_link']
        artist.seeking_description = request.form['seeking_description']
        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
        if error:
            flash('An error occurred. Artist ' +
                  request.form['name'] + ' could not be listed.')
        else:
            flash('Artist ' + request.form['name'] +
                  ' was successfully listed!')
        return render_template('pages/home.html')
示例#4
0
def create_artist_submission():
    form = ArtistForm()
    if form.validate_on_submit():
        try:
            artist = Artist()
            artist.name = request.form['name']
            artist.city = request.form['city']
            artist.state = request.form['state']
            artist.phone = request.form['phone']
            artist.image_link = request.form['image_link']
            artist.genres = request.form.getlist('genres')
            artist.facebook_link = request.form['facebook_link']
            artist.website = request.form['website']
            artist.seeking_venue = True if 'seeking_venue' in request.form else False
            artist.seeking_description = request.form['seeking_description']
            db.session.add(artist)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            flash(
                'An error occurred. Artist {} Could not be listed!, {}'.format(
                    request.form['name'], str(e)))
        finally:
            db.session.close()
            flash('Artist {} was successfully listed!'.format(
                request.form['name']))
            return redirect(url_for('artists'))
    return render_template('forms/new_artist.html', form=form)
示例#5
0
def create_artist_submission():
    data = Artist()
    error = False
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    try:
        data.name = request.form['name']
        data.city = request.form['city']
        data.state = request.form['state']
        data.phone = request.form['phone']
        data.genres = ','.join(request.form.getlist('genres'))
        data.facebook_link = request.form['facebook_link']

        db.session.add(data)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Artist ' + data.name +
              ' could not be listed.')
    finally:
        # on successful db insert, flash success
        if error == False:
            flash('Artist ' + request.form['name'] +
                  ' was successfully listed!')
    return render_template('pages/home.html')
示例#6
0
def create_artist_submission():
    error = False
    try:
        # TODO: insert form data as a new artist record in the db, instead
        artist = Artist()
        artist.name = request.form['name']
        artist.city = request.form['city']
        state = State.query.filter_by(name=request.form['state']).first()
        artist.state = state
        artist.phone = request.form['phone']
        for name in request.form.getlist('genres'):
            genre = Genre.query.filter_by(name=name).first()
            artist.genres.append(genre)
        artist.facebook_link = request.form['facebook_link']

        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Artist ' + request.form['name'] +
              ' could not be listed.')
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    # TODO: modify data to be the data object returned from db insertion
    # on successful db insert, flash success
    if not error:
        # on successful db insert, flash success
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    return render_template('pages/home.html')
示例#7
0
def create_artist_submission():
  # called upon submitting the new artist listing form
  # 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
  form = ArtistForm(request.form)

  try:
    artist = Artist()

    artist.name = request.form.get('name')
    artist.city = request.form.get('city')
    artist.state = request.form.get('state')
    artist.phone = request.form.get('phone')
    artist.genres = form.genres.data
    artist.image_link = request.form.get('image_link', None)
    artist.facebook_link = request.form.get('facebook_link', None)
    artist.website = request.form.get('website', None)
    artist.seeking_venue = boolean_check(request.form.get('seeking_venue', None))
    artist.seeking_description = request.form.get('seeking_description', False)

    artist.insert()

    # on successful db insert, flash success
    flash('Artist ' + request.form['name'] + ' was successfully listed!')
  except:
    flash('An error occurred. Artist ' + request.form['name'] + ' could not be listed.')
  # TODO: on unsuccessful db insert, flash an error instead.
  # e.g., flash('An error occurred. Venue ' + data.name + ' could not be listed.')
  return render_template('pages/home.html')
示例#8
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    errorFlag = False
    try:
        artist = Artist()
        submission = request.form
        artist.city = submission['city']
        artist.facebook_link = submission['facebook_link']
        artist.genres = submission.getlist('genres')
        artist.image_link = submission['image_link']
        artist.name = submission['name']
        artist.phone = submission['phone']
        artist.seeking_description = submission['seeking_description']
        artist.seeking_venue = True if 'seeking_venue' in submission else False
        artist.state = submission['state']
        artist.website = submission['website']
        db.session.add(artist)
        db.session.commit()
    except Exception as e:
        errorFlag = True
        db.session.rollback()
    finally:
        db.session.close()
    if not errorFlag:
        # on successful db insert, flash success
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    else:
        # on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Artist ' + request.form['name'] +
              ' could not be listed.')
    return render_template('pages/home.html')
示例#9
0
def create_artist_submission():
    form = ArtistForm(request.form)
    new_artist = Artist()
    new_artist.name = form.name.data
    new_artist.city = form.city.data
    new_artist.state = form.state.data
    new_artist.genres = form.genres.data
    new_artist.phone = form.phone.data
    new_artist.facebook_link = form.facebook_link.data
    new_artist.image_link = form.image_link.data
    new_artist.website = form.website.data
    new_artist.seeking_description = form.seeking_description.data
    new_artist.seeking_talent = form.seeking_talent.data
    try:
        db.session.add(new_artist)
        db.session.commit()
        # on successful db insert, flash success
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    except:
        db.session.rollback()
        # TODO: on unsuccessful db insert, flash an error instead.
        flash('An error occurred. Artist ' + new_artist.name +
              ' could not be listed.')
    finally:
        db.session.close()
    return render_template('pages/home.html')
示例#10
0
文件: app.py 项目: AbdoAnany/fyyur
def create_artist_submission():
    form = ArtistForm(request.form)
    try:
        artist = Artist()
        form.populate_obj(artist)
        db.session.add(artist)
        db.session.commit()
        flash('  validate Thank You   .')
    except ValueError as e:
        print(e)
        flash(' Error  You input Invalidate Please Try again  .')
        db.session.rollback()
    finally:
        db.session.close()
    error = False
    artist = Artist()
    if (request.form['seeking_description'] != None):
        artist.seeking_venue = True
    artist.name = request.form['name']
    artist.city = request.form['city']
    artist.state = request.form['state']
    artist.phone = request.form['phone']
    artist.genres = request.form.getlist('genres')
    artist.website = request.form['website']
    artist.seeking_description = request.form['seeking_description']
    artist.facebook_link = request.form['facebook_link']
    artist.image_link = request.form['image_link']
    try:

        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        #TODO: on unsuccessful db insert, flash an error instead.

        flash('An error occurred. Venue ' + request.form['name'] +
              ' could not be listed.')

    finally:
        db.session.close()
    if error:
        error = True
    else:
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
        return render_template('pages/home.html')
示例#11
0
def save_changes(album, form, new=False):
    """ Save the changes to the database """
    # Get data from form and assign it to the correct attributes
    # of the SQLAlchemy table object
    artist = Artist()
    artist.name = form.artist.data

    album.artist = artist
    album.title = form.title.data
    album.release_date = form.release_date.data
    album.publisher = form.publisher.data
    album.media_type = form.media_type.data

    if new:
        # Add the new album to the database
        db_session.add(album)

    db_session.commit()
示例#12
0
def addArtistData():
    artists = Artist.query.all()
    # only load data if db is empty
    if (not len(artists)):
        for defaultArtist in artists_default_data:
            artist = Artist()
            artist.city = defaultArtist['city']
            artist.facebook_link = defaultArtist['facebook_link']
            artist.genres = defaultArtist['genres']
            artist.image_link = defaultArtist['image_link']
            artist.name = defaultArtist['name']
            artist.phone = defaultArtist['phone']
            artist.seeking_description = defaultArtist['seeking_description']
            artist.seeking_venue = defaultArtist['seeking_venue']
            artist.state = defaultArtist['state']
            artist.website = defaultArtist['website']
            db.session.add(artist)
        db.session.commit()
示例#13
0
def get_artist_entry(item):
    artist_raw = item.get('Creator')
    name = parse_artist_name(artist_raw)

    artist = Artist.query.filter_by(name=name).first()

    if not artist:
        birth, death = parse_artist_dates(artist_raw)

        artist = Artist()
        artist.name = name
        artist.culture = parse_artist_culture(artist_raw)
        artist.birth = birth
        artist.death = death

        db.session.add(artist)

    return artist
示例#14
0
def save_changes(album, form, new=False):
    """
    Save the changes to the database
    """
    # сравнием данные с базой и сохраняем изменения

    artist = Artist()
    artist.name = form.artist.data

    album.artist = artist
    album.title = form.title.data
    album.release_date = form.release_date.data
    album.publisher = form.publisher.data
    album.media_type = form.media_type.data

    if new:
        # добавляем новый альбом в базу
        db_session.add(album)

    # комитим в базу
    db_session.commit()
示例#15
0
def save_changes(song, form, new=False):
    """
    Save the changes to the database
    """
    # Get data from form and assign it to the correct attributes
    # of the SQLAlchemy table object
    artist = Artist()
    artist.name = form.artist.data

    song.artist = artist
    song.song = form.song.data
    song.mp3_file = form.mp3_file.data
    print(form.mp3_file.data)

    if new:
        # Add the new album to the database
        song.rank = 1600
        db_session.add(song)

    # commit the data to the database
    db_session.commit()
示例#16
0
def create_artist_submission():
  # called upon submitting the new artist listing form
  error = False
  try:
    website = ''
    seeking_venue = False
    seeking_description = ''
    image_link = ''
    if 'seeking_venue' in request.form:
      seeking_venue = request.form['seeking_venue']
    if 'seeking_description' in request.form:
      seeking_description = request.form['seeking_description']
    if 'website' in request.form:
      website = request.form['website']
    if 'image_link' in request.form:
      image_link = request.form['image_link']
    artist = Artist()
    artist.name = request.form['name']
    artist.city = request.form['city']
    artist.state = request.form['state']
    artist.phone = request.form['phone']
    artist.genres = ','.join(request.form.getlist('genres'))
    artist.facebook_link = request.form['facebook_link']
    artist.image_link = image_link
    artist.website = website
    artist.seeking_venue = seeking_venue
    artist.seeking_description = seeking_description
    db.session.add(artist)
    db.session.commit()
  except Exception as e:
      error = True
      print(f'Error ==> {e}')
      db.session.rollback()
  finally:
      db.session.close()
      if error: flash('An error occurred. Artist ' + request.form['name'] + ' could not be listed.')
      else: flash('Artist ' + request.form['name'] +' was successfully listed!')

  return render_template('pages/home.html')
示例#17
0
文件: app.py 项目: OAK06/FSND
def create_artist_submission():
  # called upon submitting the new artist listing form
  # TODO: insert form data as a new Venue record in the db, instead - DONE
  # TODO: modify data to be the data object returned from db insertion - DONE
  # TODO: on unsuccessful db insert, flash an error instead. - DONE
  # e.g., flash('An error occurred. Artist ' + data.name + ' could not be listed.')
  form = ArtistForm(request.form, meta={'csrf': False})
  if form.validate():
    try:
      artist = Artist()
      artist.name = request.form.get('name', '')
      artist.city = request.form.get('city', '')
      artist.state = request.form.get('state', '')
      artist.phone = request.form.get('phone', '')
      artist.image_link = request.form.get('image_link', '')
      artist.genres = json.dumps(request.form.getlist('genres'))
      if (request.form.get('seeking_venue', False) == 'y'):
        artist.seeking_venue = True
      else:
        artist.seeking_venue = False
      artist.seeking_description = request.form.get('seeking_description', '')
      artist.website = request.form.get('website', '')
      artist.facebook_link = request.form.get('facebook_link', '')
      db.session.add(artist)
      db.session.commit()
      # on successful db insert, flash success
      flash('Artist ' + request.form['name'] + ' was successfully listed!')
    except:
      db.session.rollback()
      # on unsuccessful db insert, flash an error
      flash('An error occurred. Artist ' + artist.name + ' could not be listed.')
    finally:
      return render_template('pages/home.html')
  else:
    message = []
    for field, err in form.errors.items():
      message.append(field + ' ' + '|'.join(err))
    flash('Errors ' + str(message))
    return render_template('pages/home.html')
示例#18
0
def create_artist_submission():
    error = False
    form = ArtistForm()
    try:
        name = form.name.data
        if (db.session.query(Artist.name).filter_by(name=name).scalar()
                is not None):
            flash('The artist : "' + name + '" already exists', 'error')
            return render_template('forms/new_artist.html', form=form)
        form.validate()
        if (len(form.phone.errors) > 0):
            flash(','.join(form.phone.errors))
            return render_template('forms/new_artist.html', form=form)
        artist = Artist()
        artist.name = name
        artist.city = form.city.data
        artist.state = form.state.data
        artist.phone = format_phone(form.phone.data)
        artist.genres = ','.join(request.form.getlist('genres'))
        artist.facebook_link = form.facebook_link.data
        artist.website = form.website.data
        artist.image_link = form.image_link.data
        artist.seeking_venues = form.seeking_venues.data
        artist.seeking_description = form.seeking_description.data
        db.session.add(artist)
        db.session.commit()
    except Exception as e:
        error = True
        db.session.rollback()
    finally:
        db.session.close()
    if error:
        flash(
            'An error occured. artist ' + request.form['name'] +
            ' Could not be listed.', 'error')
    else:
        flash('Artist ' + request.form['name'] + ' was successfully listed.')
    return render_template('pages/home.html')
示例#19
0
文件: app.py 项目: tobischroeder/FSND
def create_artist_submission():
  error = False
  try:
    data = request.form
    artist = Artist()
    artist.name = data['name']
    genres = []
    for (k, v) in data.items(multi=True):
      if k == 'genres':
        genres.append(v)
    artist.genres = genres
    artist.city = data['city']
    artist.state = data['state']
    artist.phone = data['phone']
    artist.website = data['website']
    artist.facebook_link = data['facebook_link']
    artist.seeking_venue = 'seeking_venue' in data
    artist.seeking_description = data['seeking_description']
    artist.image_link = data['image_link']

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

  finally:
    db.session.close()
  
  if error:
    flash('ERROR: Artist ' + request.form['name'] + ' could not be listed!')
  else:
    flash('Artist ' + request.form['name'] + ' was successfully listed!')
  
  return render_template('pages/home.html')
示例#20
0
def create_artist_submission():
    form = ArtistForm()
    if form.validate_on_submit():
        try:
            artist = Artist()
            artist.name = form.name.data
            artist.city_id = get_city_id(form.city.data, form.state.data)
            artist.phone = form.phone.data
            artist.image_link = form.image.data
            artist.facebook_link = form.facebook.data
            artist.website = form.website.data
            artist.seeking_venue = form.isSeeking.data
            artist.seeking_description = form.seekingDesc.data
            artist.genres = form.genres.data
            db.session.add(artist)
            db.session.commit()
            flash('Artist ' + artist.name + ' was successfully listed!')
        except Exception as e:
            flash('An error occurred: ' + str(e))
            db.session.rollback()
        finally:
            db.session.close()
        return redirect(url_for('artists'))
    return render_template('forms/new_artist.html', form=form)
示例#21
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # 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

    form = ArtistForm()
    error = False
    try:
        artist = Artist()
        artist.name = request.form['name']
        artist.city = request.form['city']
        artist.state = request.form['state']
        artist.phone = request.form['phone']
        tmp_genres = request.form.getlist('genres')
        artist.genres = ','.join(tmp_genres)
        artist.website = request.form['website']
        artist.image_link = request.form['image_link']
        artist.facebook_link = request.form['facebook_link']
        artist.seeking_description = request.form['seeking_description']
        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
        # TODO: on unsuccessful db insert, flash an error instead.
        if error:
            flash('An error occurred. Artist ' + request.form['name'] +
                  ' could not be listed.')
        else:
            # on successful db insert, flash success
            flash('Artist ' + request.form['name'] +
                  ' was successfully listed!')
        return render_template('pages/home.html')