Example #1
0
def shows():
    # displays list of shows at /shows
    # TODO: replace with real venues data.

    # a query of all shows from db using join
    show_query = Show.query.options(db.joinedload(Show.Venue),
                                    db.joinedload(Show.Artist)).all()
    data = list(map(Show.detail, show_query))
    return render_template('pages/shows.html', shows=data)
Example #2
0
def show_artist(artist_id):
    artist = Artist.query.get(artist_id)
    data = {}
    if artist:
        upcoming_shows = Show.query.options(db.joinedload(Show.Artist)).filter(
            Show.artist_id == artist_id).filter(Show.start_time > now).all()
        past_shows = Show.query.options(db.joinedload(Show.Artist)).filter(
            Show.artist_id == artist_id).filter(Show.start_time < now).all()
        data = artist.show_details()
        data['past_shows'] = [show.show_venue() for show in past_shows]
        data['upcoming_shows_count'] = len(upcoming_shows)
    return render_template('pages/show_artist.html', artist=data)
Example #3
0
def show_venue(venue_id):
    venue = Venue.query.get(venue_id)
    print(venue)
    data = {}
    if venue:
        past_shows = Show.query.options(db.joinedload(Show.Venue)).filter(Show.venue_id == venue_id)\
            .filter(Show.start_time <= now).all()
        upcoming_shows = Show.query.options(db.joinedload(Show.Venue)).filter(Show.venue_id == venue_id)\
            .filter(Show.start_time > now).all()
        data = venue.show_details()
        data["past_shows"] = list(map(Show.show_artist, past_shows))
        data["upcoming_shows"] = list(map(Show.show_artist, upcoming_shows))
        data["past_shows_count"] = len(past_shows)
        data["upcoming_shows_count"] = len(upcoming_shows)

    return render_template('pages/show_venue.html', venue=data)
Example #4
0
def search_artists():
    # TODO: implement search on artists with partial string search. Ensure it is case-insensitive.
    # seach for "A" should return "Guns N Petals", "Matt Quevado", and "The Wild Sax Band".
    # search for "band" should return "The Wild Sax Band".
    search_term = request.form.get('search_term')
    found_artists = Artist.query.filter(
        Artist.name.ilike('%{}%'.format(search_term))).all()
    response = {
        "count":
        len(found_artists),
        "data": [{
            "id":
            artist.id,
            "name":
            artist.name,
            "num_upcoming_shows":
            len(
                Show.query.options(db.joinedload(
                    Show.Artist)).filter(Show.artist_id == artist.id).filter(
                        Show.start_time > now).all()),
        } for artist in found_artists]
    }
    return render_template('pages/search_artists.html',
                           results=response,
                           search_term=request.form.get('search_term', ''))
Example #5
0
def phone_list_eager():
    """Get list of users & dept phones.

    This version will be a single query because of the eager
    joined load.
    """

    emps = Employee.query.options(db.joinedload('dept')).all()
    return render_template("phones.html", emps=emps)
Example #6
0
def show_actor(token, actor_id):
    actor_query = Actors.query.get(actor_id).show()
    if not actor_query:
        abort(404)
    movies_featured = [movie_set.movie_id for movie_set in
                       Sets.query.options(db.joinedload(Sets.actors))
                           .filter(Sets.actor_id == actor_id).all()]
    return jsonify({
        'actor': actor_query,
        'movies_featured_in': len(movies_featured)
    })
Example #7
0
def show_venue(venue_id):
    venue_query = Venue.query.get(venue_id)

    if venue_query:
        venue_details = Venue.detail(venue_query)
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        new_shows_query = Show.query.options(db.joinedload(
            Show.Venue)).filter(Show.venue_id == venue_id).filter(
                Show.start_time > current_time).all()
        new_show = list(map(Show.artist_details, new_shows_query))
        venue_details["upcoming_shows"] = new_show
        venue_details["upcoming_shows_count"] = len(new_show)
        past_shows_query = Show.query.options(db.joinedload(
            Show.Venue)).filter(Show.venue_id == venue_id).filter(
                Show.start_time <= current_time).all()
        past_shows = list(map(Show.artist_details, past_shows_query))
        venue_details["past_shows"] = past_shows
        venue_details["past_shows_count"] = len(past_shows)
    print(venue_details)

    return render_template('pages/show_venue.html', venue=venue_details)
    return render_template('errors/404.html')
Example #8
0
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')
Example #9
0
def search_venues():
    # TODO: implement search on artists with partial string search. Ensure it is case-insensitive.
    # seach for Hop should return "The Musical Hop".
    # search for "Music" should return "The Musical Hop" and "Park Square Live Music & Coffee"
    search_term = request.form["search_term"]
    found_venues = Venue.query.filter(
        Venue.name.ilike("%{}%".format(search_term))).all()
    print(found_venues)
    data_list = []
    for venue in found_venues:
        current_venue = {}
        current_venue["id"] = venue.id
        current_venue["name"] = venue.name
        current_venue["num_upcoming_shows"] = len(Show.query.options(db.joinedload(Show.Venue)).\
            filter(Show.venue_id == venue.id).all())
        data_list.append(current_venue)
    response = {"count": len(found_venues), "data": data_list}
    return render_template('pages/search_venues.html',
                           results=response,
                           search_term=request.form.get('search_term', ''))
Example #10
0
def main():
    context = {
        'courses': sort_courses(models.Course.query.options(db.joinedload('exams')).all()),
        'breadcrumbs': [{'name': 'Emner'}]
    }
    return render_template('courses.html', **context)
Example #11
0
def shows():
    show_query = Show.query.options(db.joinedload(Show.Venue),
                                    db.joinedload(Show.Artist)).all()
    data = list(map(Show.detail, show_query))
    return render_template('pages/shows.html', shows=data)