def show_artist(artist_id): # shows the artist page with the given artist_id # TODO: replace with real Artist data from the Artist table, using artist_id artist_details = {} try: artist_query = Artist.query.get(artist_id) if artist_query: artist_details = Artist.details(artist_query) current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') show_query = Show.query.options(db.joinedload( Show.Artist)).filter(Show.artist_id == artist_id) upcoming_show_list = list( map(Show.artist_details(), show_query.filter(Show.date_time > current_time).all())) past_show_list = list( map(Show.artist_details(), show_query.filter(Show.date_time <= current_time).all())) artist_details["upcoming_shows"] = upcoming_show_list artist_details["upcoming_shows_count"] = len(upcoming_show_list) artist_details["past_shows"] = past_show_list artist_details["past_shows_count"] = len(past_show_list) except: db.session.rollback() finally: db.session.close() if artist_details: return render_template('pages/show_artist.html', artist=artist_details) else: return render_template('errors/404.html')