Example #1
0
def get_movie_reviews_by_title(title: str, repo: AbstractRepository):
    movie = repo.get_movie_by_title(title)
    if movie is None:
        raise NonExistentMovieException
    reviews = repo.get_movie_reviews(movie)
    reviews.sort(reverse=True, key=lambda r: r.timestamp)
    return util_services.reviews_to_dict(reviews)
Example #2
0
def get_genre_batch_dict(genre_id: int, repo: AbstractRepository, limit=9):
    genre = repo.get_genre_by_id(genre_id)
    movies = repo.get_movies_by_genre(genre)
    batch_list = [movies[i:i + limit] for i in range(0, len(movies), limit)]
    for batch in batch_list:
        util_services.movies_to_dict(batch)
    return batch_list
Example #3
0
def add_review(movie_id: int, review_text: str, rating: int, user_name: str,
               repo: AbstractRepository):
    movie = repo.get_movie_by_id(movie_id)
    if movie is None:
        raise NonExistentMovieException
    user = repo.get_user(user_name)
    if user is None:
        raise UnknownUserException
    review = Review(movie=movie,
                    review_text=review_text,
                    rating=rating,
                    user=user)
    repo.add_review(review)
Example #4
0
def get_movie_labels(repo: AbstractRepository):
    movies = repo.get_movies()
    movies.sort()
    movies_dict = movies_to_dict(movies)
    for movies in movies_dict:
        movies['url'] = url_for('movie_bp.movie_by_id', id=movies['id'])
    return movies_dict
Example #5
0
def auth_user(user_name: str, password: str, repo: AbstractRepository):
    auth = False
    user = repo.get_user(user_name)
    if user is not None:
        auth = check_password_hash(user.password, password)
    if not auth:
        raise AuthenticationException
Example #6
0
def get_actor_labels(repo: AbstractRepository):
    actors = repo.get_actors()
    actors.sort()
    actors_dict = util_services.actors_to_dict(actors)
    for actor in actors_dict:
        actor['url'] = url_for('browse_bp.browse_by_actor', id=actor['id'])
    return actors_dict
Example #7
0
def get_genre_labels(repo: AbstractRepository):
    genres = repo.get_genres()
    genres.sort()
    genres_dict = util_services.genres_to_dict(genres)
    for genre in genres_dict:
        genre['url'] = url_for('browse_bp.browse_by_genre', id=genre['id'])
    return genres_dict
Example #8
0
def get_watchlist(user_name: str, repo: AbstractRepository):
    user = repo.get_user(user_name)
    watchlist = user.watchlist
    watchlist_dict = util_services.movies_to_dict(watchlist.watchlist)
    for movie in watchlist_dict:
        movie['rm_url'] = url_for('watchlist_bp.remove_from_watchlist', id=movie['id'])
        movie['review_url'] = url_for('review_bp.submit_review', id=movie['id'])
    return watchlist_dict
Example #9
0
def get_director_labels(repo: AbstractRepository):
    directors = repo.get_directors()
    directors.sort()
    directors_dict = util_services.directors_to_dict(directors)
    for directors in directors_dict:
        directors['url'] = url_for('browse_bp.browse_by_director',
                                   id=directors['id'])
    return directors_dict
Example #10
0
def get_user(user_name: str, repo: AbstractRepository):
    user = repo.get_user(user_name)
    if user is None:
        raise UnknownUserException
    return util_services.user_to_dict(user)
Example #11
0
def add_user(user_name: str, password: str, first_name: str, last_name: str,
             repo: AbstractRepository):
    if repo.get_user(user_name) is not None:
        raise NameNotUniqueException
    password_hash = generate_password_hash(password)
    repo.add_user(User(user_name, password_hash, first_name, last_name))
Example #12
0
def get_movies_by_id(id_list: list, repo: AbstractRepository):
    movies = repo.get_movies_by_id(id_list)
    return movies_to_dict(movies)
Example #13
0
def get_actor_subtitle(actor_id: int, repo: AbstractRepository):
    actor = repo.get_actor_by_id(actor_id)
    return 'Showing results for ' + actor.actor_full_name
Example #14
0
def get_movie_by_title(title: str, repo: AbstractRepository):
    return util_services.movie_to_dict(repo.get_movie_by_title(title))
Example #15
0
def get_director_movies(director_id: int, repo: AbstractRepository):
    director = repo.get_director_by_id(director_id)
    movies = repo.get_movies_by_director(director)
    return util_services.movies_to_dict(movies)
Example #16
0
def get_genre_movies(genre_id: int, repo: AbstractRepository):
    genre = repo.get_genre_by_id(genre_id)
    movies = repo.get_movies_by_genre(genre)
    return util_services.movies_to_dict(movies)
Example #17
0
def get_movie(movie_id: int, repo: AbstractRepository):
    movie = repo.get_movie_by_id(movie_id)
    if movie is None:
        raise NonExistentMovieException
    return movie_to_dict(movie)
Example #18
0
def get_movie_subtitle(movie_id: int, repo: AbstractRepository):
    movie = repo.get_movie_by_id(movie_id)
    return 'Showing results for ' + movie.title
Example #19
0
def get_director_subtitle(director_id: int, repo: AbstractRepository):
    director = repo.get_director_by_id(director_id)
    return 'Showing results for ' + director.director_full_name
Example #20
0
def remove_from_watchlist(movie_id: int, user_name: str, repo: AbstractRepository):
    user = repo.get_user(user_name)
    movie = repo.get_movie_by_id(movie_id)
    user.watchlist.remove_movie(movie)
Example #21
0
def get_genre_subtitle(genre_id: int, repo: AbstractRepository):
    genre = repo.get_genre_by_id(genre_id)
    return 'Showing results for the ' + genre.genre_type + ' genre'
Example #22
0
def add_to_watchlist(movie_id: int, user_name: str, repo: AbstractRepository):
    user = repo.get_user(user_name)
    movie = repo.get_movie_by_id(movie_id)
    user.watchlist.add_movie(movie)
Example #23
0
def get_random_movies(quantity, repo: AbstractRepository):
    movie_count = len(repo.get_movies())
    random_ids = random.sample(range(1, movie_count), quantity)
    movies = repo.get_movies_by_rank(random_ids)
    movies_dict = movies_to_dict(movies)
    return movies_dict