def movies_box(user_id): y = ynbox("Chcesz filtrować wyniki?", title) if y: filter_box(user_id) else: movies = f.get_name_list_from_cursor(f.show_all_objects(movies_col)) choice = choicebox(msg="Wybierz film", title=title, choices=movies) if choice is not None: display_movie_box(choice, user_id) else: menu_box(user_id)
def reviews_of_movie_box(movie_name, user_id): reviews = f.find_movie_reviews(movie_name, movies_col, reviews_col) if reviews.count() == 0: msgbox("Ten film nie ma ocen", title) menu_box(user_id) else: review_names = [] review_objects = [] for review in reviews: review_objects.append(review) review_names.append( f.get_name_of_object(review['user_id'], users_col)) choice = choicebox("Recenzje filmu:", title, review_names) review_box(user_id, review_objects[review_names.index(choice)], movie_name)
def filter_box(user_id): choice = choicebox("Wybierz kategorię", title, choices=["gatunek", "reżyser", "rok produkcji"]) made_a_choice = True movies = None if choice is None: check_continue_browsing_box(user_id) else: if choice == "gatunek": genre = choicebox("Wybierz gatunki", title, genres_set) if genre is not None: movies = f.get_name_list_from_cursor( f.find_movie_by_category(genre, movies_col)) else: made_a_choice = False elif choice == "reżyser": director = enterbox(msg="Podaj imię i nazwisko reżysera", title=title) if director is not None: movies = f.get_name_list_from_cursor( f.find_movie_by_director(director, movies_col)) else: made_a_choice = False elif choice == "rok produkcji": if ynbox("Czy chcesz wybra rok produkcji jako przedział?", title): year0 = integerbox("Podaj początek przedziału", title, upperbound=10000) year = integerbox("Podaj koniec przedziału", title, upperbound=10000) if year0 is not None and year is not None: movies = f.get_name_list_from_cursor( f.find_movie_by_year_margin(year0, year, movies_col)) else: made_a_choice = False else: year = integerbox("Podaj rok", title, upperbound=10000) if year is not None: movies = f.get_name_list_from_cursor( f.find_movie_by_year(year, movies_col)) else: made_a_choice = False else: made_a_choice = False if made_a_choice: if len(movies) == 1: display_movie_box(movies[0], user_id) elif len(movies) > 0: choice = choicebox(msg="Wybierz film", title=title, choices=movies) display_movie_box(choice, user_id) else: msgbox("Nie znaleziono filmów spełniających wybrane kryteria", title) check_continue_browsing_box(user_id) else: check_continue_browsing_box(user_id)
def review_box(user_id, review, movie_name): author = f.get_name_of_object(review["user_id"], users_col) msgbox( "Autor recenzji: " + author + "\n" + "Tytuł: " + movie_name + "\n" + "Ocena: " + str(review["rating"]) + "\n" + "Recenzja: " + "\n" + str(review["text"]), title) menu_box(user_id)
def my_reviews_box(user_id): reviews = f.find_user_reviews(user_id, reviews_col) if reviews.count() == 0: msgbox("Nie oceniłeś/aś żadnych filmów", title) menu_box(user_id) else: reviews_names_obj = {} for review in reviews: movie_id = review["movie_id"] reviews_names_obj[f.get_name_of_object(movie_id, movies_col)] = review reviews_names = [] for name in reviews_names_obj.keys(): reviews_names.append(name) choice = choicebox("Twoje oceny", title, reviews_names) chosen_review = reviews_names_obj[choice] review_box(user_id, chosen_review, choice)
def display_movie_box(movie_name, user_id): movie_cursor = f.find_object_by_name(movie_name, movies_col) movie = movie_cursor[0] genres = "" for i in movie["genres"]: genres += i genres += ", " rat = f.average_rating(movie["_id"], reviews_col) if rat is None: rat = "Brak ocen" else: rat = "Średnia ocen: " + str(rat) choice = buttonbox( movie["name"] + "\n" + "Gatunki: " + genres + "\n" + "Reżyser: " + movie["director"] + "\n" + rat + "\n" + "Ilość recenzji: " + str(f.count_movie_reviews(movie["name"], movies_col, reviews_col)), title, ["Oceń", "Wyjdź", "Oceny"]) if choice == "Oceń": add_review_box(movie["_id"], user_id) elif choice == "Oceny": reviews_of_movie_box(movie_name, user_id) else: check_continue_browsing_box(user_id)
def review_added(user_id, movie_id): msgbox( "Pomyślnie dodano recenzję filmu " + str(f.get_name_of_object(movie_id, movies_col)), title) menu_box(user_id)