Exemplo n.º 1
0
def test_get_page_items():
    big_list = [i for i in range(1, 1001)]
    small_list = [i for i in range(1, 5)]

    assert get_page_items(1, 6, big_list) == ([1, 2, 3, 4, 5, 6], None, 2)
    assert get_page_items(167, 6, big_list) == ([997, 998, 999,
                                                 1000], 166, None)
    assert get_page_items(20, 5, big_list) == ([96, 97, 98, 99, 100], 19, 21)

    assert get_page_items(1, 10, small_list) == ([1, 2, 3, 4], None, None)
Exemplo n.º 2
0
def get_page_items_movies_search(search_query: str, match_threshold: float, current_page_num: int,
                                 results_per_page: int,
                                 repo: AbstractRepository):
    search_result_set = []
    for movie in repo.get_all_movies():
        movie_str = build_movie_string(movie)
        tk_set_ratio = token_set_ratio(search_query, movie_str)
        if tk_set_ratio > match_threshold:
            search_result_set.append((tk_set_ratio, movie))

    search_result_set.sort(reverse=True)

    movies_obj_tuple_list, prev_page, next_page = get_page_items(current_page_num, results_per_page, search_result_set)
    number_pages = get_number_pages(results_per_page, len(search_result_set))
    number_results = len(search_result_set)

    return search_tuple_to_movies_dict(movies_obj_tuple_list), prev_page, next_page, number_pages, number_results
Exemplo n.º 3
0
def genres():
    genres_per_page = 8

    current_page = request.args.get('page')

    if current_page is None:
        current_page = 1

    current_page = int(current_page)

    first_page = 1
    last_page = get_number_pages(genres_per_page,
                                 repo.repo_instance.get_number_genres())

    genres_list, prev_page, next_page = get_page_items(
        current_page, genres_per_page, repo.repo_instance.get_all_genres())

    first_page_url = None
    last_page_url = None
    next_page_url = None
    prev_page_url = None

    if len(genres_list) > 0:
        if prev_page is not None:
            first_page_url = url_for('genres_bp.genres', page=first_page)
            prev_page_url = url_for('genres_bp.genres', page=prev_page)
        if next_page is not None:
            last_page_url = url_for('genres_bp.genres', page=last_page)
            next_page_url = url_for('genres_bp.genres', page=next_page)

    return render_template('genres/genres.html',
                           genres=genres_list,
                           first_page_url=first_page_url,
                           last_page_url=last_page_url,
                           next_page_url=next_page_url,
                           prev_page_url=prev_page_url)
Exemplo n.º 4
0
def get_page_items_movies_for_genre(genre, current_page_str, results_per_page,
                                    repo: AbstractRepository):
    movies_obj_list, prev_page, next_page = get_page_items(
        int(current_page_str), results_per_page,
        repo.get_movies_for_genre(Genre(genre)))
    return movies_to_dict(movies_obj_list), prev_page, next_page