Skip to content

Commit

Permalink
feat: Enable updating artist and venue
Browse files Browse the repository at this point in the history
  • Loading branch information
saelsa committed Oct 18, 2019
1 parent 36cf02f commit 6b6467d
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,32 @@ def edit_artist(artist_id):

@app.route('/artists/<int:artist_id>/edit', methods=['POST'])
def edit_artist_submission(artist_id):
# TODO: take values from the form submitted, and update existing
# artist record with ID <artist_id> using the new attributes
error = False
artist = Artist.query.get(artist_id)

try:
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.image_link = request.form['image_link']
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.commit()
except:
error = True
db.session.rollback()
print(sys.exc_info())
finally:
db.session.close()
if error:
flash('An error occurred. Artist could not be changed.')
if not error:
flash('Artist was successfully updated!')
return redirect(url_for('show_artist', artist_id=artist_id))

@app.route('/venues/<int:venue_id>/edit', methods=['GET'])
Expand All @@ -337,8 +360,33 @@ def edit_venue(venue_id):

@app.route('/venues/<int:venue_id>/edit', methods=['POST'])
def edit_venue_submission(venue_id):
# TODO: take values from the form submitted, and update existing
# venue record with ID <venue_id> using the new attributes
error = False
venue = Venue.query.get(venue_id)

try:
venue.name = request.form['name']
venue.city = request.form['city']
venue.state = request.form['state']
venue.address = request.form['address']
venue.phone = request.form['phone']
venue.genres = request.form.getlist('genres')
venue.image_link = request.form['image_link']
venue.facebook_link = request.form['facebook_link']
venue.website = request.form['website']
venue.seeking_talent = True if 'seeking_talent' in request.form else False
venue.seeking_description = request.form['seeking_description']

db.session.commit()
except:
error = True
db.session.rollback()
print(sys.exc_info())
finally:
db.session.close()
if error:
flash(f'An error occurred. Venue could not be changed.')
if not error:
flash(f'Venue was successfully updated!')
return redirect(url_for('show_venue', venue_id=venue_id))

# Create Artist
Expand Down

0 comments on commit 6b6467d

Please sign in to comment.