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)
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
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)
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
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
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
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
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
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
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)
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))
def get_movies_by_id(id_list: list, repo: AbstractRepository): movies = repo.get_movies_by_id(id_list) return movies_to_dict(movies)
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
def get_movie_by_title(title: str, repo: AbstractRepository): return util_services.movie_to_dict(repo.get_movie_by_title(title))
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)
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)
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)
def get_movie_subtitle(movie_id: int, repo: AbstractRepository): movie = repo.get_movie_by_id(movie_id) return 'Showing results for ' + movie.title
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
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)
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'
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)
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