コード例 #1
0
ファイル: home.py プロジェクト: ParDaydreamer/CS235-FLIX-A2
def home():
    return render_template(
        'home/home.html',
        genre_urls=utilities.get_genres_and_urls(),
        year_urls=utilities.get_year_and_urls(),
        director_urls=utilities.get_directors_and_urls(),
        actor_urls=utilities.get_actors_and_urls(),
        home_movies=utilities.get_selected_movies(6),
    )
コード例 #2
0
ファイル: feed.py プロジェクト: ParDaydreamer/CS235-FLIX-A3
def movies_by_genre():
    movies_per_page = 4

    # Read query parameters.
    genre_name = request.args.get('genre')
    cursor = request.args.get('cursor')
    movie_to_show_comments = request.args.get('view_comments_for')

    if movie_to_show_comments is None:
        # No view-comments query parameter, so set to a non-existent movie rank.
        movie_to_show_comments = -1
    else:
        # Convert movie_to_show_comments from string to int.
        movie_to_show_comments = int(movie_to_show_comments)

    if cursor is None:
        # No cursor query parameter, so initialise cursor to start at the beginning.
        cursor = 0
    else:
        # Convert cursor from string to int.
        cursor = int(cursor)

    # Retrieve movie ids for movies that are genreged with genre_name.
    movie_ranks = services.get_movie_ranks_for_genre(genre_name, repo.repo_instance)

    # Retrieve the batch of movies to display on the Web page.
    movies = services.get_movies_by_rank(movie_ranks[cursor:cursor + movies_per_page], repo.repo_instance)

    first_movie_url = None
    last_movie_url = None
    next_movie_url = None
    prev_movie_url = None

    if cursor > 0:
        # There are preceding movies, so generate URLs for the 'previous' and 'first' navigation buttons.
        prev_movie_url = url_for('feed_bp.movies_by_genre', genre=genre_name, cursor=cursor - movies_per_page)
        first_movie_url = url_for('feed_bp.movies_by_genre', genre=genre_name)

    if cursor + movies_per_page < len(movie_ranks):
        # There are further movies, so generate URLs for the 'next' and 'last' navigation buttons.
        next_movie_url = url_for('feed_bp.movies_by_genre', genre=genre_name, cursor=cursor + movies_per_page)

        last_cursor = movies_per_page * int(len(movie_ranks) / movies_per_page)
        if len(movie_ranks) % movies_per_page == 0:
            last_cursor -= movies_per_page
        last_movie_url = url_for('feed_bp.movies_by_genre', genre=genre_name, cursor=last_cursor)

    # Construct urls for viewing movie comments and adding comments.
    for movie in movies:
        movie['view_comment_url'] = url_for('feed_bp.movies_by_genre', genre=genre_name, cursor=cursor, view_comments_for=movie['rank'])
        movie['add_comment_url'] = url_for('feed_bp.comment_on_movie', movie=movie['rank'])

    # Generate the webpage to display the movies.
    return render_template(
        'feed/movies.html',
        title='Movies',
        movies_title=genre_name + ' movies',
        movies=movies,
        selected_movies=utilities.get_selected_movies(len(movies) * 2),
        genre_urls=utilities.get_genres_and_urls(),
        year_urls=utilities.get_year_and_urls(),
        director_urls=utilities.get_directors_and_urls(),
        actor_urls=utilities.get_actors_and_urls(),
        first_movie_url=first_movie_url,
        last_movie_url=last_movie_url,
        prev_movie_url=prev_movie_url,
        next_movie_url=next_movie_url,
        show_comments_for_movie=movie_to_show_comments
    )