diff --git a/projects/01_fyyur/starter_code/app.py b/projects/01_fyyur/starter_code/app.py index b30c04a42a2..432686cd213 100644 --- a/projects/01_fyyur/starter_code/app.py +++ b/projects/01_fyyur/starter_code/app.py @@ -1,6 +1,6 @@ -#----------------------------------------------------------------------------# -# Imports -#----------------------------------------------------------------------------# +#==========================================================================# +# IMPORTS +#==========================================================================# import json import dateutil.parser @@ -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) @@ -23,9 +24,9 @@ # TODO: connect to a local postgresql database -#----------------------------------------------------------------------------# -# Models. -#----------------------------------------------------------------------------# +#==========================================================================# +# MODELS +#==========================================================================# class Venue(db.Model): __tablename__ = 'Venue' @@ -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) @@ -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 # ---------------------------------------------------------------- @@ -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(): @@ -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/') def show_venue(venue_id): @@ -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 # ---------------------------------------------------------------- @@ -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//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 + return render_template('forms/edit_venue.html', form=form, venue=venue) + +@app.route('/venues//edit', methods=['POST']) +def edit_venue_submission(venue_id): + # TODO: take values from the form submitted, and update existing + # venue record with ID using the new attributes + return redirect(url_for('show_venue', venue_id=venue_id)) + +# ---------------------------------------------------------------- +# Delete Venue +# ---------------------------------------------------------------- @app.route('/venues/', methods=['DELETE']) def delete_venue(venue_id): @@ -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 @@ -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(): @@ -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/') def show_artist(artist_id): @@ -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//edit', methods=['GET']) def edit_artist(artist_id): form = ArtistForm() @@ -376,53 +453,7 @@ def edit_artist_submission(artist_id): return redirect(url_for('show_artist', artist_id=artist_id)) -@app.route('/venues//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 - return render_template('forms/edit_venue.html', form=form, venue=venue) - -@app.route('/venues//edit', methods=['POST']) -def edit_venue_submission(venue_id): - # TODO: take values from the form submitted, and update existing - # venue record with 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 # ---------------------------------------------------------------- @@ -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(): @@ -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): @@ -506,9 +545,9 @@ def server_error(error): app.logger.addHandler(file_handler) app.logger.info('errors') -#----------------------------------------------------------------------------# -# Launch. -#----------------------------------------------------------------------------# +#==========================================================================# +# LAUNCH +#==========================================================================# # Default port: if __name__ == '__main__': diff --git a/projects/01_fyyur/starter_code/forms.py b/projects/01_fyyur/starter_code/forms.py index 42771beb5dd..0992b7d898f 100644 --- a/projects/01_fyyur/starter_code/forms.py +++ b/projects/01_fyyur/starter_code/forms.py @@ -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): @@ -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 @@ -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( @@ -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()], @@ -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 diff --git a/projects/01_fyyur/starter_code/requirements.txt b/projects/01_fyyur/starter_code/requirements.txt index 31f089f5ba4..a55bb78f8ea 100755 --- a/projects/01_fyyur/starter_code/requirements.txt +++ b/projects/01_fyyur/starter_code/requirements.txt @@ -1,4 +1,7 @@ babel -python-dateutil==2.6.0 +datetime +python-dateutil==2.8.1 flask-moment -flask-wtf \ No newline at end of file +flask-wtf +flask-sqlalchemy +flask-migrate \ No newline at end of file diff --git a/projects/01_fyyur/starter_code/templates/forms/edit_artist.html b/projects/01_fyyur/starter_code/templates/forms/edit_artist.html index 87036546900..4f9ac211be1 100644 --- a/projects/01_fyyur/starter_code/templates/forms/edit_artist.html +++ b/projects/01_fyyur/starter_code/templates/forms/edit_artist.html @@ -1,38 +1,64 @@ {% extends 'layouts/main.html' %} {% block title %}Edit Artist{% endblock %} {% block content %} -
-
-

Edit artist {{ artist.name }}

-
- - {{ form.name(class_ = 'form-control', autofocus = true) }} -
-
- -
-
- {{ form.city(class_ = 'form-control', placeholder='City', autofocus = true) }} -
-
- {{ form.state(class_ = 'form-control', placeholder='State', autofocus = true) }} -
-
-
-
- - {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', autofocus = true) }} +
+ +

{{ artist.name }}

+
+ + {{ form.name(class_ = 'form-control', autofocus = true) }} +
+
+ +
+
+ {{ form.city(class_ = 'form-control', placeholder='City', autofocus = + true) }}
-
- - Ctrl+Click to select multiple - {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by commas', id=form.state, autofocus = true) }} -
-
- - {{ form.facebook_link(class_ = 'form-control', placeholder='http://', id=form.state, autofocus = true) }} +
+ {{ form.state(class_ = 'form-control', placeholder='State', autofocus + = true) }}
- - -
+
+
+
+ + {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', + autofocus = true) }} +
+
+ + Ctrl+Click to select multiple + {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by + commas', autofocus = true) }} +
+
+ + Upload a photo + {{ form.image_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Facebook link + {{ form.facebook_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Website Link + {{ form.website(class_ = 'form-control', autofocus = true) }} +
+
+ + Are you Looking for a new venue? + {{ form.seeking_venue(class_ = 'form-control', autofocus = true) }} +
+
+ + What are you looking for? + {{ form.seeking_description(class_ = 'form-control', autofocus = true) }} +
+ + +
{% endblock %} \ No newline at end of file diff --git a/projects/01_fyyur/starter_code/templates/forms/edit_venue.html b/projects/01_fyyur/starter_code/templates/forms/edit_venue.html index 1c3469f1bb9..bfe9526bd2f 100644 --- a/projects/01_fyyur/starter_code/templates/forms/edit_venue.html +++ b/projects/01_fyyur/starter_code/templates/forms/edit_venue.html @@ -1,42 +1,68 @@ {% extends 'layouts/main.html' %} {% block title %}Edit Venue{% endblock %} {% block content %} -
-
-

Edit venue {{ venue.name }}

-
- - {{ form.name(class_ = 'form-control', autofocus = true) }} -
-
- -
-
- {{ form.city(class_ = 'form-control', placeholder='City', autofocus = true) }} -
-
- {{ form.state(class_ = 'form-control', placeholder='State', autofocus = true) }} -
-
-
-
- - {{ form.address(class_ = 'form-control', autofocus = true) }} -
-
- - {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', autofocus = true) }} +
+ +

{{ venue.name }}

+
+ + {{ form.name(class_ = 'form-control', autofocus = true) }} +
+
+ +
+
+ {{ form.city(class_ = 'form-control', placeholder='City', autofocus = + true) }}
-
- - Ctrl+Click to select multiple - {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by commas', id=form.state, autofocus = true) }} -
-
- - {{ form.facebook_link(class_ = 'form-control', placeholder='http://', id=form.state, autofocus = true) }} +
+ {{ form.state(class_ = 'form-control', placeholder='State', autofocus + = true) }}
- - -
+
+
+
+ + {{ form.address(class_ = 'form-control', autofocus = true) }} +
+
+ + {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', + autofocus = true) }} +
+
+ + Ctrl+Click to select multiple + {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by + commas', autofocus = true) }} +
+
+ + Upload a photo + {{ form.image_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Facebook link + {{ form.facebook_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Website Link + {{ form.website(class_ = 'form-control', autofocus = true) }} +
+
+ + Are you Looking for new talent? + {{ form.seeking_talent(class_ = 'form-control', autofocus = true) }} +
+
+ + What are you looking for? + {{ form.seeking_description(class_ = 'form-control', autofocus = true) }} +
+ + +
{% endblock %} \ No newline at end of file diff --git a/projects/01_fyyur/starter_code/templates/forms/new_artist.html b/projects/01_fyyur/starter_code/templates/forms/new_artist.html index 33062fa2777..fe1900895f1 100644 --- a/projects/01_fyyur/starter_code/templates/forms/new_artist.html +++ b/projects/01_fyyur/starter_code/templates/forms/new_artist.html @@ -1,38 +1,63 @@ {% extends 'layouts/main.html' %} {% block title %}New Artist{% endblock %} {% block content %} -
-
-

List a new artist

-
- - {{ form.name(class_ = 'form-control', autofocus = true) }} -
-
- -
-
- {{ form.city(class_ = 'form-control', placeholder='City', autofocus = true) }} -
-
- {{ form.state(class_ = 'form-control', placeholder='State', autofocus = true) }} -
-
-
-
- - {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', autofocus = true) }} +
+ +

List a new artist

+
+ + {{ form.name(class_ = 'form-control', autofocus = true) }} +
+
+ +
+
+ {{ form.city(class_ = 'form-control', placeholder='City', autofocus = + true) }}
-
- - Ctrl+Click to select multiple - {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by commas', id=form.state, autofocus = true) }} -
-
- - {{ form.facebook_link(class_ = 'form-control', placeholder='http://', id=form.state, autofocus = true) }} +
+ {{ form.state(class_ = 'form-control', placeholder='State', autofocus + = true) }}
- - -
+
+
+
+ + {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', + autofocus = true) }} +
+
+ + Ctrl+Click to select multiple + {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by + commas', autofocus = true) }} +
+
+ + Upload a photo + {{ form.image_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Facebook link + {{ form.facebook_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Website Link + {{ form.website(class_ = 'form-control', autofocus = true) }} +
+
+ + Are you Looking for a new venue? + {{ form.seeking_venue(class_ = 'form-control', autofocus = true) }} +
+
+ + What are you looking for? + {{ form.seeking_description(class_ = 'form-control', autofocus = true) }} +
+ + +
{% endblock %} \ No newline at end of file diff --git a/projects/01_fyyur/starter_code/templates/forms/new_venue.html b/projects/01_fyyur/starter_code/templates/forms/new_venue.html index a0bc91ae27d..e4a5a7ef3e7 100644 --- a/projects/01_fyyur/starter_code/templates/forms/new_venue.html +++ b/projects/01_fyyur/starter_code/templates/forms/new_venue.html @@ -1,42 +1,69 @@ -{% extends 'layouts/main.html' %} -{% block title %}New Venue{% endblock %} -{% block content %} -
-
-

List a new venue

-
- - {{ form.name(class_ = 'form-control', autofocus = true) }} -
-
- -
-
- {{ form.city(class_ = 'form-control', placeholder='City', autofocus = true) }} -
-
- {{ form.state(class_ = 'form-control', placeholder='State', autofocus = true) }} -
-
-
-
- - {{ form.address(class_ = 'form-control', autofocus = true) }} -
-
- - {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', autofocus = true) }} +{% extends 'layouts/main.html' %} {% block title %}New Venue{% endblock %} {% + block content %} +
+ +

+ List a new venue + +

+
+ + {{ form.name(class_ = 'form-control', autofocus = true) }} +
+
+ +
+
+ {{ form.city(class_ = 'form-control', placeholder='City', autofocus = + true) }}
-
- - Ctrl+Click to select multiple - {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by commas', id=form.state, autofocus = true) }} -
-
- - {{ form.facebook_link(class_ = 'form-control', placeholder='http://', id=form.state, autofocus = true) }} +
+ {{ form.state(class_ = 'form-control', placeholder='State', autofocus + = true) }}
- - -
+
+
+
+ + {{ form.address(class_ = 'form-control', autofocus = true) }} +
+
+ + {{ form.phone(class_ = 'form-control', placeholder='xxx-xxx-xxxx', + autofocus = true) }} +
+
+ + Ctrl+Click to select multiple + {{ form.genres(class_ = 'form-control', placeholder='Genres, separated by + commas', autofocus = true) }} +
+
+ + Upload a photo + {{ form.image_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Facebook link + {{ form.facebook_link(class_ = 'form-control', autofocus = true) }} +
+
+ + Website Link + {{ form.website(class_ = 'form-control', autofocus = true) }} +
+
+ + Are you Looking for new talent? + {{ form.seeking_talent(class_ = 'form-control', autofocus = true) }} +
+
+ + What are you looking for? + {{ form.seeking_description(class_ = 'form-control', autofocus = true) }} +
+ + +
{% endblock %} \ No newline at end of file