Exemplo n.º 1
0
def review_movie():
    form = ReviewForm()

    movie = services.movie_to_dict(
        repo.repo_instance.get_movie(request.args.get('title'),
                                     int(request.args.get('year'))))
    movie['poster_url'] = get_movie_poster_url(movie['title'],
                                               movie['release_year'])

    if form.validate_on_submit():
        # Add the review to the DB
        if 'username' not in session:
            return redirect(url_for('authentication_bp.login'))
        services.add_review(movie['title'], movie['release_year'],
                            form.review_text.data, form.review_rating.data,
                            session['username'], repo.repo_instance)

        # Reload the page
        return redirect(request.url)

    # GET or failed POST, either way load page with form

    form.movie_title.data = movie['title']
    form.movie_release_year.data = movie['release_year']

    return render_template('movies/movie_reviews.html', movie=movie, form=form)
Exemplo n.º 2
0
def movies_by_genre():
    genre_name = request.args.get('genre')
    current_page = request.args.get('page')

    if current_page is None:
        current_page = 1

    current_page = int(current_page)

    first_page = 1
    last_page = services.get_number_pages_movies_for_genre(
        genre_name, movies_per_page, repo.repo_instance)

    movies_dict, prev_page, next_page = services.get_page_items_movies_for_genre(
        genre_name, current_page, movies_per_page, repo.repo_instance)

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

    if len(movies_dict) > 0:
        if prev_page is not None:
            prev_page_url = url_for('movies_bp.movies_by_genre',
                                    genre=genre_name,
                                    page=prev_page)
            first_page_url = url_for('movies_bp.movies_by_genre',
                                     genre=genre_name,
                                     page=first_page)
        if next_page is not None:
            next_page_url = url_for('movies_bp.movies_by_genre',
                                    genre=genre_name,
                                    page=next_page)
            last_page_url = url_for('movies_bp.movies_by_genre',
                                    genre=genre_name,
                                    page=last_page)

        for movie in movies_dict:
            movie['add_review_url'] = url_for('movies_bp.review_movie',
                                              title=movie['title'],
                                              year=movie['release_year'])
            movie['poster_url'] = get_movie_poster_url(movie['title'],
                                                       movie['release_year'])

        return render_template(
            'movies/movies.html',
            movies_page_title="Browsing movies with tag: " + genre_name,
            movies=movies_dict,
            first_movie_url=first_page_url,
            last_movie_url=last_page_url,
            next_movie_url=next_page_url,
            prev_movie_url=prev_page_url,
        )

    return redirect(url_for('home_bp.home'))
Exemplo n.º 3
0
def search():
    search_query = request.args.get('q')
    page = request.args.get('page')

    if page is None:
        page = 1

    page = int(page)

    first_page = 1

    movies_dict, prev_page, next_page, last_page, number_results = services.get_page_items_movies_search(
        search_query, match_threshold, page, results_per_page,
        repo.repo_instance)

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

    if len(movies_dict) > 0:
        if prev_page is not None:
            prev_movie_url = url_for('search_bp.search',
                                     q=search_query,
                                     page=prev_page)
            first_movie_url = url_for('search_bp.search',
                                      q=search_query,
                                      page=first_page)
        if next_page is not None:
            next_movie_url = url_for('search_bp.search',
                                     q=search_query,
                                     page=next_page)
            last_movie_url = url_for('search_bp.search',
                                     q=search_query,
                                     page=last_page)

        for movie in movies_dict:
            movie['add_review_url'] = url_for('movies_bp.review_movie',
                                              title=movie['title'],
                                              year=movie['release_year'])
            movie['poster_url'] = get_movie_poster_url(movie['title'],
                                                       movie['release_year'])

    return render_template(
        'movies/movies.html',
        movies_page_title="Search for " + search_query + " yielded " +
        str(number_results) + " results",
        movies=movies_dict,
        first_movie_url=first_movie_url,
        last_movie_url=last_movie_url,
        next_movie_url=next_movie_url,
        prev_movie_url=prev_movie_url,
    )
Exemplo n.º 4
0
def test_get_valid_poster_movie_url():
    assert get_movie_poster_url("Guardians of the Galaxy", 2014) == \
           "https://m.media-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SX600.jpg", \
        "This may fail if the API is down, visit OMDB to check"