Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 106 additions & 67 deletions projects/01_fyyur/starter_code/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#----------------------------------------------------------------------------#
# Imports
#----------------------------------------------------------------------------#
#==========================================================================#
# IMPORTS
#==========================================================================#

import json
import dateutil.parser
Expand All @@ -12,9 +12,10 @@
from logging import Formatter, FileHandler
from flask_wtf import Form
from forms import *
#----------------------------------------------------------------------------#
# App Config.
#----------------------------------------------------------------------------#

#==========================================================================#
# APP CONFIG
#==========================================================================#

app = Flask(__name__)
moment = Moment(app)
Expand All @@ -23,9 +24,9 @@

# TODO: connect to a local postgresql database

#----------------------------------------------------------------------------#
# Models.
#----------------------------------------------------------------------------#
#==========================================================================#
# MODELS
#==========================================================================#

class Venue(db.Model):
__tablename__ = 'Venue'
Expand Down Expand Up @@ -55,11 +56,11 @@ class Artist(db.Model):

# TODO: implement any missing fields, as a database migration using Flask-Migrate

# TODO Implement Show and Artist models, and complete all model relationships and properties, as a database migration.
# TODO: Implement Show model, and complete all model relationships and properties, as a database migration.

#----------------------------------------------------------------------------#
# Filters.
#----------------------------------------------------------------------------#
#==========================================================================#
# FILTERS
#==========================================================================#

def format_datetime(value, format='medium'):
date = dateutil.parser.parse(value)
Expand All @@ -71,15 +72,15 @@ def format_datetime(value, format='medium'):

app.jinja_env.filters['datetime'] = format_datetime

#----------------------------------------------------------------------------#
# Controllers.
#----------------------------------------------------------------------------#
#==========================================================================#
# CONTROLLERS
#==========================================================================#

@app.route('/')
def index():
return render_template('pages/home.html')


# ----------------------------------------------------------------
# Venues
# ----------------------------------------------------------------

Expand Down Expand Up @@ -109,6 +110,10 @@ def venues():
}]
}]
return render_template('pages/venues.html', areas=data);

# ----------------------------------------------------------------
# Venues Search
# ----------------------------------------------------------------

@app.route('/venues/search', methods=['POST'])
def search_venues():
Expand All @@ -124,6 +129,10 @@ def search_venues():
}]
}
return render_template('pages/search_venues.html', results=response, search_term=request.form.get('search_term', ''))

# ----------------------------------------------------------------
# Venue Page
# ----------------------------------------------------------------

@app.route('/venues/<int:venue_id>')
def show_venue(venue_id):
Expand Down Expand Up @@ -209,6 +218,7 @@ def show_venue(venue_id):
data = list(filter(lambda d: d['id'] == venue_id, [data1, data2, data3]))[0]
return render_template('pages/show_venue.html', venue=data)

# ----------------------------------------------------------------
# Create Venue
# ----------------------------------------------------------------

Expand All @@ -228,6 +238,40 @@ def create_venue_submission():
# 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('pages/home.html')

# ----------------------------------------------------------------
# Edit Venue
# ----------------------------------------------------------------

@app.route('/venues/<int:venue_id>/edit', methods=['GET'])
def edit_venue(venue_id):
form = VenueForm()
venue={
"id": 1,
"name": "The Musical Hop",
"genres": ["Jazz", "Reggae", "Swing", "Classical", "Folk"],
"address": "1015 Folsom Street",
"city": "San Francisco",
"state": "CA",
"phone": "123-123-1234",
"website": "https://www.themusicalhop.com",
"facebook_link": "https://www.facebook.com/TheMusicalHop",
"seeking_talent": True,
"seeking_description": "We are on the lookout for a local artist to play every two weeks. Please call us.",
"image_link": "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60"
}
# TODO: populate form with values from venue with ID <venue_id>
return render_template('forms/edit_venue.html', form=form, venue=venue)

@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
return redirect(url_for('show_venue', venue_id=venue_id))

# ----------------------------------------------------------------
# Delete Venue
# ----------------------------------------------------------------

@app.route('/venues/<venue_id>', methods=['DELETE'])
def delete_venue(venue_id):
Expand All @@ -238,8 +282,10 @@ def delete_venue(venue_id):
# clicking that button delete it from the db then redirect the user to the homepage
return None

# ----------------------------------------------------------------
# Artists
# ----------------------------------------------------------------

@app.route('/artists')
def artists():
# TODO: replace with real data returned from querying the database
Expand All @@ -254,6 +300,10 @@ def artists():
"name": "The Wild Sax Band",
}]
return render_template('pages/artists.html', artists=data)

# ----------------------------------------------------------------
# Artists Search
# ----------------------------------------------------------------

@app.route('/artists/search', methods=['POST'])
def search_artists():
Expand All @@ -269,6 +319,10 @@ def search_artists():
}]
}
return render_template('pages/search_artists.html', results=response, search_term=request.form.get('search_term', ''))

# ----------------------------------------------------------------
# Artist
# ----------------------------------------------------------------

@app.route('/artists/<int:artist_id>')
def show_artist(artist_id):
Expand Down Expand Up @@ -347,9 +401,32 @@ def show_artist(artist_id):
}
data = list(filter(lambda d: d['id'] == artist_id, [data1, data2, data3]))[0]
return render_template('pages/show_artist.html', artist=data)

# ----------------------------------------------------------------
# Create Artist
# ----------------------------------------------------------------

@app.route('/artists/create', methods=['GET'])
def create_artist_form():
form = ArtistForm()
return render_template('forms/new_artist.html', form=form)

@app.route('/artists/create', methods=['POST'])
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

# 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')

# Update
# ----------------------------------------------------------------
# Update Artist
# ----------------------------------------------------------------

@app.route('/artists/<int:artist_id>/edit', methods=['GET'])
def edit_artist(artist_id):
form = ArtistForm()
Expand All @@ -376,53 +453,7 @@ def edit_artist_submission(artist_id):

return redirect(url_for('show_artist', artist_id=artist_id))

@app.route('/venues/<int:venue_id>/edit', methods=['GET'])
def edit_venue(venue_id):
form = VenueForm()
venue={
"id": 1,
"name": "The Musical Hop",
"genres": ["Jazz", "Reggae", "Swing", "Classical", "Folk"],
"address": "1015 Folsom Street",
"city": "San Francisco",
"state": "CA",
"phone": "123-123-1234",
"website": "https://www.themusicalhop.com",
"facebook_link": "https://www.facebook.com/TheMusicalHop",
"seeking_talent": True,
"seeking_description": "We are on the lookout for a local artist to play every two weeks. Please call us.",
"image_link": "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60"
}
# TODO: populate form with values from venue with ID <venue_id>
return render_template('forms/edit_venue.html', form=form, venue=venue)

@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
return redirect(url_for('show_venue', venue_id=venue_id))

# Create Artist
# ----------------------------------------------------------------

@app.route('/artists/create', methods=['GET'])
def create_artist_form():
form = ArtistForm()
return render_template('forms/new_artist.html', form=form)

@app.route('/artists/create', methods=['POST'])
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

# 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')


# Shows
# ----------------------------------------------------------------

Expand Down Expand Up @@ -468,6 +499,10 @@ def shows():
"start_time": "2035-04-15T20:00:00.000Z"
}]
return render_template('pages/shows.html', shows=data)

# ----------------------------------------------------------------
# Create Show
# ----------------------------------------------------------------

@app.route('/shows/create')
def create_shows():
Expand All @@ -486,6 +521,10 @@ def create_show_submission():
# 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')

#==========================================================================#
# ERROR HANDLERS
#==========================================================================#

@app.errorhandler(404)
def not_found_error(error):
Expand All @@ -506,9 +545,9 @@ def server_error(error):
app.logger.addHandler(file_handler)
app.logger.info('errors')

#----------------------------------------------------------------------------#
# Launch.
#----------------------------------------------------------------------------#
#==========================================================================#
# LAUNCH
#==========================================================================#

# Default port:
if __name__ == '__main__':
Expand Down
36 changes: 26 additions & 10 deletions projects/01_fyyur/starter_code/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from flask_wtf import Form
from wtforms import StringField, SelectField, SelectMultipleField, DateTimeField
from wtforms import StringField, SelectField, SelectMultipleField, DateTimeField, BooleanField
from wtforms.validators import DataRequired, AnyOf, URL

class ShowForm(Form):
Expand Down Expand Up @@ -83,10 +83,7 @@ class VenueForm(Form):
'address', validators=[DataRequired()]
)
phone = StringField(
'phone'
)
image_link = StringField(
'image_link'
'phone', validators=[DataRequired()]
)
genres = SelectMultipleField(
# TODO implement enum restriction
Expand All @@ -113,9 +110,21 @@ class VenueForm(Form):
('Other', 'Other'),
]
)
image_link = StringField(
'image_link'
)
facebook_link = StringField(
'facebook_link', validators=[URL()]
)
website = StringField(
'website', validators=[URL()]
)
seeking_talent = BooleanField(
'seeking_talent'
)
seeking_description = StringField(
'seeking_description'
)

class ArtistForm(Form):
name = StringField(
Expand Down Expand Up @@ -181,12 +190,8 @@ class ArtistForm(Form):
]
)
phone = StringField(
# TODO implement validation logic for state
'phone'
)
image_link = StringField(
'image_link'
)
genres = SelectMultipleField(
# TODO implement enum restriction
'genres', validators=[DataRequired()],
Expand All @@ -212,9 +217,20 @@ class ArtistForm(Form):
('Other', 'Other'),
]
)
image_link = StringField(
'image_link'
)
facebook_link = StringField(
# TODO implement enum restriction
'facebook_link', validators=[URL()]
)
website = StringField(
'website', validators=[URL()]
)
seeking_venue = BooleanField(
'seeking_venue'
)
seeking_description = StringField(
'seeking_description'
)

# TODO IMPLEMENT NEW ARTIST FORM AND NEW SHOW FORM
7 changes: 5 additions & 2 deletions projects/01_fyyur/starter_code/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
babel
python-dateutil==2.6.0
datetime
python-dateutil==2.8.1
flask-moment
flask-wtf
flask-wtf
flask-sqlalchemy
flask-migrate
Loading