예제 #1
0
파일: movies.py 프로젝트: imbapc/COMPSCIA2
def search():
    form = SearchForm(request.form)
    if form.validate():
        search_data = form.search.data
        category = request.form.get('category')
        result = utilities.find_movie(search_data, category)
        return render_template(
            'result.html',
            result=result,
            random_movies=utilities.get_random_movie(3),
        )
    return render_template(
        'searchbar.html',
        form=form,
        random_movies=utilities.get_random_movie(3),
    )
예제 #2
0
파일: movies.py 프로젝트: imbapc/COMPSCIA2
def movie(title, year):
    target_movie = utilities.get_movie(title, year)
    utilities.add_popularity(target_movie)
    review_list = utilities.get_reviews(target_movie.id)
    add_review_url = url_for('movie_bp.review_on_movie',
                             movie_id=target_movie.id)
    return render_template('movie/movie.html',
                           content_movie=target_movie,
                           random_movies=utilities.get_random_movie(3),
                           review_list=review_list,
                           add_review_url=add_review_url)
예제 #3
0
파일: movies.py 프로젝트: imbapc/COMPSCIA2
def review_on_movie():
    # Obtain the username of the currently logged in user.
    username = session['username']
    user = utilities.get_user(username)

    # Create form. The form maintains state, e.g. when this method is called with a HTTP GET request and populates
    # the form with an article id, when subsequently called with a HTTP POST request, the article id remains in the
    # form.
    form = ReviewForm()

    if form.validate_on_submit():
        # Successful POST, i.e. the review text has passed data validation.
        # Extract the article id, representing the reviewed movie, from the form.
        movie_id = int(form.movie_id.data)

        # Retrieve the article in dict form.
        movie_result = services.get_movie_by_id(movie_id, repo.repo_instance)

        # Use the service layer to store the new review.
        services.add_review(repo.repo_instance, form.review.data, movie_result,
                            form.rating.data, user)

        # Cause the web browser to display the page of all movies that have the same date as the reviewed movie,
        # and display all reviews, including the new review.
        return redirect(
            url_for('movie_bp.movie',
                    title=movie_result.title,
                    year=movie_result.year))

    if request.method == 'GET':
        # Request is a HTTP GET to display the form.
        # Extract the article id, representing the movie to review, from a query parameter of the GET request.
        movie_id = int(request.args.get('movie_id'))

        # Store the article id in the form.
        form.movie_id.data = movie_id
    else:
        # Request is a HTTP POST where form validation has failed.
        # Extract the article id of the article being reviewed from the form.
        movie_id = int(form.movie_id.data)

    # For a GET or an unsuccessful POST, retrieve the article to review in dict form, and return a Web page that allows
    # the user to enter a review. The generated Web page includes a form object.
    content_movie = services.get_movie_by_id(movie_id, repo.repo_instance)
    return render_template('movie/review.html',
                           content_movie=content_movie,
                           random_movies=utilities.get_random_movie(3),
                           handler_url=url_for('movie_bp.review_on_movie'),
                           form=form)
예제 #4
0
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, repo.repo_instance)

            # Authenticate user.
            services.authenticate_user(user['username'], form.password.data, repo.repo_instance)

            # 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,
        random_movies=utilities.get_random_movie(3)
    )
예제 #5
0
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, repo.repo_instance)

            # 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'),
        random_movies=utilities.get_random_movie(3)
    )
예제 #6
0
파일: home.py 프로젝트: imbapc/COMPSCIA2
def home():
    return render_template('home/home.html',
                           popular_movies=utilities.get_popular_movies(),
                           recent_movies=utilities.get_recent_movies(),
                           random_movies=utilities.get_random_movie(3))
예제 #7
0
파일: movies.py 프로젝트: imbapc/COMPSCIA2
def director(director_full_name):
    target_director = utilities.get_director(director_full_name)
    return render_template('movie/director.html',
                           director=target_director,
                           random_movies=utilities.get_random_movie(3))
예제 #8
0
파일: movies.py 프로젝트: imbapc/COMPSCIA2
def actor(actor_full_name):
    target_actor = utilities.get_actor(actor_full_name)
    return render_template('movie/actor.html',
                           actor=target_actor,
                           random_movies=utilities.get_random_movie(3))