Exemplo n.º 1
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.º 2
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.º 3
0
def get_number_pages_movies_for_genre(genre, results_per_page,
                                      repo: AbstractRepository):
    return get_number_pages(results_per_page,
                            repo.get_number_movies_for_genre(Genre(genre)))
Exemplo n.º 4
0
def test_get_number_pages():
    assert get_number_pages(6, 1000) == 167
    assert get_number_pages(5, 10) == 2
    assert get_number_pages(10, 5) == 1
Exemplo n.º 5
0
def get_number_pages_movies(results_per_page, repo: AbstractRepository):
    return get_number_pages(results_per_page, repo.get_number_movies())