def director_search(): text = request.form['text'] if text == "": return browse_by_director() else: search_results = services.search_director(text) return render_template('movie/dir_page.html', message=f"Directors related to {text.capitalize()}", list_of_directors=search_results, watchlist=utilities.get_watchlist())
def user_page(): try: rev_tr = True reviews = services.get_user_reviews(session['username']) if not len(reviews): rev_tr = False return render_template("authentication/user_page.html", rev_tr=rev_tr, reviews=reviews, username=session['username'], watchlist=utilities.get_watchlist()) except AttributeError: session.clear() return redirect(url_for('home_bp.home'))
def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to attempt to add the new user. try: services.add_user(form.username.data, form.password.data) # All is well, redirect the user to the login page. return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = 'Your username is already taken - please supply another' # For a GET or a failed POST request, return the Registration Web page. return render_template('authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, handler_url=url_for('authentication_bp.register'), TandC=True, watchlist=utilities.get_watchlist())
def login(): form = LoginForm() username_not_recognised = None password_does_not_match_username = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to lookup the user. try: user = services.get_user(form.username.data) # Authenticate user. services.authenticate_user(user['username'], form.password.data) # Initialise session and redirect the user to the home page. session.clear() session['username'] = user['username'] return redirect(url_for('home_bp.home')) except services.UnknownUserException: # Username not known to the system, set a suitable error message. username_not_recognised = 'Username not recognised - please supply another' except services.AuthenticationException: # Authentication failed, set a suitable error message. password_does_not_match_username = '******' # For a GET or a failed POST, return the Login Web page. return render_template( 'authentication/credentials.html', title='Login', username_error_message=username_not_recognised, password_error_message=password_does_not_match_username, form=form, TandC=False, watchlist=utilities.get_watchlist())
def show_movies_from_director(dir_of_choice): chosen_movie_list = services.get_movies_from_director(dir_of_choice) chosen_movie_list.sort() return render_template('movie/browse.html', list_of_movies=chosen_movie_list, message=f"Browsing all Movies directed by {dir_of_choice}", search_val=False, watchlist=utilities.get_watchlist())
def browse_by_director(): directors = services.get_directors() directors.sort() return render_template('movie/dir_page.html', message=f"Browsing all Directors", list_of_directors=directors, watchlist=utilities.get_watchlist())
def browse_by_actor(): actors = services.get_actors() actors.sort() return render_template('movie/actor_page.html', message="Browsing all Actors", list_of_actors=actors, watchlist=utilities.get_watchlist())
def gen_name_search(genre): text = request.form['text'] if text == "": return browse_by_name() else: search_results = services.search_genre(text, genre) return render_template('movie/Browse_gen.html', list_of_movies=search_results, message=f"{genre} movies related to {text.capitalize()}", search_val=True, watchlist=utilities.get_watchlist())
def show_movies_in_genre(gen_of_choice): chosen_movie_list = services.get_movies_from_genre(gen_of_choice) chosen_movie_list.sort() return render_template('movie/browse_gen.html', list_of_movies=chosen_movie_list, message=f"Browsing all {gen_of_choice} Movies ", watchlist=utilities.get_watchlist())
def browse_by_genre(): genres = services.get_genres() genres.sort() return render_template('movie/genre_page.html', list_of_genres=genres, watchlist=utilities.get_watchlist())
def browse_by_name(): return render_template('movie/Browse.html', list_of_movies=services.get_movies_by_name(), message="Browse all of our Movies in Name order", search_val=True, watchlist=utilities.get_watchlist())
def show_movie(hyperlink): rev_tr = False mov = services.get_movie(hyperlink) reviews = mov.get_reviews() if not len(reviews): rev_tr = True return render_template('movie/movie_disp.html', rev_tr=rev_tr, reviews=reviews, title="Movie Details", movie=mov, watchlist=utilities.get_watchlist())
def home(): if 'username' in session: message = f"Here is a selection of movies we think you'll love {session['username']}!" else: message = "Here is a selection of movies we think you'll love!" return render_template('home/home.html', message=message, selected_movies=utilities.get_selected_movies(), watchlist=utilities.get_watchlist())