def show_artist(artist_id): # Shows the artist page with the given artist_id artist = Artist.query.filter_by(id=artist_id).first_or_404() past_shows = db.session.query(Venue, Show).join(Show).join(Artist). \ filter( Show.artist_id == artist_id, Show.venue_id == Venue.id, Show.start_time < datetime.now() ). \ all() upcoming_shows = db.session.query(Venue, Show).join(Show).join(Artist). \ filter( Show.artist_id == artist_id, Show.venue_id == Venue.id, Show.start_time > datetime.now() ). \ all() data = Artist.detail(artist) data.update({ 'past_shows': [Show.venue_detail(show) for venue, show in past_shows], 'upcoming_shows': [Show.venue_detail(show) for venue, show in upcoming_shows], 'past_shows_count': len(past_shows), 'upcoming_shows_count': len(upcoming_shows) }) return render_template('pages/show_artist.html', artist=data)
def edit_artist(artist_id): form = ArtistForm() artist_data = Artist.query.get(artist_id) if artist_data: artist_details = Artist.detail(artist_data) form.name.data = artist_details["name"] form.genres.data = artist_details["genres"] form.city.data = artist_details["city"] form.state.data = artist_details["state"] form.phone.data = artist_details["phone"] form.website.data = artist_details["website"] form.facebook_link.data = artist_details["facebook_link"] form.seeking_venue.data = artist_details["seeking_venue"] form.seeking_description.data = artist_details["description"] form.image_link.data = artist_details["image_link"] return render_template('forms/edit_artist.html', form=form, artist=artist_details) return render_template('errors/404.html') # artist={ # "id": 4, # "name": "Guns N Petals", # "genres": ["Rock n Roll"], # "city": "San Francisco", # "state": "CA", # "phone": "326-123-5000", # "website": "https://www.gunsnpetalsband.com", # "facebook_link": "https://www.facebook.com/GunsNPetals", # "seeking_venue": True, # "seeking_description": "Looking for shows to perform at in the San Francisco Bay Area!", # "image_link": "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80" # } # # TODO: populate form with fields from artist with ID <artist_id> return render_template('forms/edit_artist.html', form=form, artist=artist)
def show_artist(artist_id): detail = Artist.query.get(artist_id) if detail is None: abort(404) else: artist = Artist.detail(detail) return render_template('pages/show_artist.html', artist=artist)
def edit_artist(artist_id): # Populate form with fields from artist with ID <artist_id> form = ArtistForm() artist_data = Artist.query.get(artist_id) artist_items = Artist.detail(artist_data) keys = [ "name", "genres", "city", "state", "phone", "website", "facebook_link", "seeking_venue", "seeking_description", "image_link" ] for key in keys: getattr(form, key).data = artist_items[key] return render_template('forms/edit_artist.html', form=form, artist=artist_items)
def edit_artist(artist_id): form = ArtistForm(request.form) artist_data = Artist.query.get(artist_id) if artist_data: artist_details = Artist.detail(artist_data) form.name.data = artist_details["name"] form.genres.data = artist_details["genres"] form.city.data = artist_details["city"] form.state.data = artist_details["state"] form.phone.data = artist_details["phone"] form.website.data = artist_details["website"] form.facebook_link.data = artist_details["facebook_link"] form.seeking_venue.data = artist_details["seeking_venue"] form.seeking_description.data = artist_details["seeking_description"] form.image_link.data = artist_details["image_link"] return render_template('forms/edit_artist.html', form=form, artist=artist_details) return render_template('errors/404.html')
def show_artist(artist_id): print(artist_id) artist_query = Artist.query.get(artist_id) if artist_query: artist_details = Artist.detail(artist_query) current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') new_shows_query = Show.query.options(db.joinedload( Show.Artist)).filter(Show.artist_id == artist_id).filter( Show.start_time > current_time).all() new_shows_list = list(map(Show.venue_details, new_shows_query)) artist_details["upcoming_shows"] = new_shows_list artist_details["upcoming_shows_count"] = len(new_shows_list) past_shows_query = Show.query.options(db.joinedload( Show.Artist)).filter(Show.artist_id == artist_id).filter( Show.start_time <= current_time).all() past_shows_list = list(map(Show.venue_details, past_shows_query)) artist_details["past_shows"] = past_shows_list artist_details["past_shows_count"] = len(past_shows_list) print(artist_details) return render_template('pages/show_artist.html', artist=artist_details) return render_template('errors/404.html')
def show_artist(artist_id): artist = Artist.query.get(artist_id) if artist: print("Got artist {} for id {}".format(artist, artist.id)) pass # Get current time with timezone dt_unware = datetime.now() localtz = get_localzone() dt_aware = localtz.localize(dt_unware) shows_before = Show.query.order_by( Show.show_time).filter(Show.show_time < dt_aware).filter( Show.artist_id == artist.id).all() num_shows_before = len(shows_before) shows_after = Show.query.order_by( Show.show_time).filter(Show.show_time >= dt_aware).filter( Show.artist_id == artist.id).all() num_shows_after = len(shows_after) artist_details = Artist.detail(artist) past_shows = [] upcoming_shows = [] for show in shows_before: venue = Venue.query.get(show.venue_id) show_time_no_tz = show.show_time.replace(tzinfo=None) # print("Object type is ", type(show_time_no_tz), show_time_no_tz) # artist_details = get_artist_details_for_venue(show.artist_id,artist.name,artist.image_link,show_time_no_tz.isoformat()) venue_details = get_venue_details_for_artist( show.venue_id, venue.name, venue.image_link, show_time_no_tz.isoformat()) past_shows.append(venue_details) for show in shows_after: venue = Venue.query.get(show.venue_id) show_time_no_tz = show.show_time.replace(tzinfo=None) venue_details = get_venue_details_for_artist( show.venue_id, venue.name, venue.image_link, show_time_no_tz.isoformat()) upcoming_shows.append(venue_details) # print("Got {} past show(s) for artist {}:{}\n".format(num_shows_before, artist.name, past_shows)) final_json = artist.detail() final_json['past_shows'] = past_shows final_json['past_shows_count'] = num_shows_before final_json['upcoming_shows'] = upcoming_shows final_json['upcoming_shows_count'] = num_shows_after # print("Got final string for artist:", final_json) return render_template('pages/show_artist.html', artist=final_json) return render_template('errors/404.html') # shows the venue page with the given venue_id # TODO: replace with real venue data from the venues table, using venue_id # data1={ # "id": 4, # "name": "Guns N Petals", # "genres": ["Rock n Roll"], # "city": "San Francisco", # "state": "CA", # "phone": "326-123-5000", # "website": "https://www.gunsnpetalsband.com", # "facebook_link": "https://www.facebook.com/GunsNPetals", # "seeking_venue": True, # "seeking_description": "Looking for shows to perform at in the San Francisco Bay Area!", # "image_link": "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80", # "past_shows": [{ # "venue_id": 1, # "venue_name": "The Musical Hop", # "venue_image_link": "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60", # "start_time": "2019-05-21T21:30:00.000Z" # }], # "upcoming_shows": [], # "past_shows_count": 1, # "upcoming_shows_count": 0, # } # data2={ # "id": 5, # "name": "Matt Quevedo", # "genres": ["Jazz"], # "city": "New York", # "state": "NY", # "phone": "300-400-5000", # "facebook_link": "https://www.facebook.com/mattquevedo923251523", # "seeking_venue": False, # "image_link": "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80", # "past_shows": [{ # "venue_id": 3, # "venue_name": "Park Square Live Music & Coffee", # "venue_image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", # "start_time": "2019-06-15T23:00:00.000Z" # }], # "upcoming_shows": [], # "past_shows_count": 1, # "upcoming_shows_count": 0, # } # data3={ # "id": 6, # "name": "The Wild Sax Band", # "genres": ["Jazz", "Classical"], # "city": "San Francisco", # "state": "CA", # "phone": "432-325-5432", # "seeking_venue": False, # "image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", # "past_shows": [], # "upcoming_shows": [{ # "venue_id": 3, # "venue_name": "Park Square Live Music & Coffee", # "venue_image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", # "start_time": "2035-04-01T20:00:00.000Z" # }, { # "venue_id": 3, # "venue_name": "Park Square Live Music & Coffee", # "venue_image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", # "start_time": "2035-04-08T20:00:00.000Z" # }, { # "venue_id": 3, # "venue_name": "Park Square Live Music & Coffee", # "venue_image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", # "start_time": "2035-04-15T20:00:00.000Z" # }], # "past_shows_count": 0, # "upcoming_shows_count": 3, # } # data = list(filter(lambda d: d['id'] == artist_id, [data1, data2, data3]))[0] return render_template('pages/show_artist.html', artist=data)