Exemplo n.º 1
0
def help():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(
            url_for('movies.title_results',
                    name=search_form.movie_title.data.lower().strip()))
    return render_template('help.html', title='Help', search_form=search_form)
Exemplo n.º 2
0
def general_error(error):
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(
            url_for('movies.title_results',
                    name=search_form.movie_title.data.lower()))

    return render_template('500.html', title='500',
                           search_form=search_form), 500
Exemplo n.º 3
0
def get_all_movies():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))
    movies = Movie.query.order_by(Movie.title).all()
    watchlist_entries = []
    for movie in movies:
        if current_user.is_authenticated:
            if WatchlistMovies.query.filter_by(userId=current_user.id, movieId=movie.movieId).first():
                watchlist_entries.append(movie)
    return render_template('all_movies.html', title='All Movies', movies=movies, search_form=search_form, watchlist_entries=watchlist_entries)
Exemplo n.º 4
0
def get_all_users():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    users = User.query.order_by(User.id).all()

    if current_user.admin:
        return render_template('all_users.html', title='All users', search_form=search_form, users=users)
    else: 
        abort(403)
Exemplo n.º 5
0
def get_watchlist(user_id):
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    movies = []

    watchlist = WatchlistMovies.query.filter_by(userId=current_user.id).all()
    for entry in watchlist:
        movie = Movie.query.filter_by(movieId=entry.movieId).first()
        movies.append(movie)
    return render_template('watchlist.html', title='Watchlist', search_form=search_form, movies=movies)
Exemplo n.º 6
0
def request_reset():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    if current_user.is_authenticated:
        flash('You are already logged in with a registered account!', 'danger')
        return redirect(url_for('movies.get_all_movies'))
    reset_form = RequestResetForm()
    if reset_form.validate_on_submit():
        user = User.query.filter_by(email=reset_form.email.data).first()
        send_reset_email(user)
        flash('An email has been sent with instructions to reset your password', 'success')
        return redirect(url_for('users.login'))
    return render_template('request_reset.html', title='Reset Password', search_form=search_form, reset_form=reset_form)
Exemplo n.º 7
0
def search_movies_by_year(year=None):
    search_form = TitleSearchForm()
    year_form = YearSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))
    if flask.request.method == 'POST' and year_form.validate_on_submit():
        return redirect(url_for('movies.search_movies_by_year', year=year_form.movie_year.data.strip()))
    count = 0
    movies = Movie.query.filter_by(year=year).order_by(Movie.title).all()
    watchlist_entries = []
    for movie in movies:
        count += 1
        if current_user.is_authenticated:
            if WatchlistMovies.query.filter_by(userId=current_user.id, movieId=movie.movieId).first():
                watchlist_entries.append(movie)
    return render_template('get_movie_by_year.html', title='Movies by year', movies=movies, search_form=search_form, year_form=year_form, year=year, count=count, watchlist_entries=watchlist_entries)
Exemplo n.º 8
0
def title_results(name, year):
    search_form = TitleSearchForm()
    results_form = ResultsSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))
    elif flask.request.method == 'POST' and results_form.validate_on_submit():
        return redirect(url_for('movies.search_for_movie', name=results_form.result_movie_title.data.lower().strip(), year=results_form.result_movie_year.data.strip()))
    count = 0
    movies = Movie.query.filter(func.lower(Movie.title).like("%{0}%".format(name.lower()))).order_by(Movie.title).all()
    watchlist_entries = []
    for movie in movies:
        count += 1
        if current_user.is_authenticated:
            if WatchlistMovies.query.filter_by(userId=current_user.id, movieId=movie.movieId).first():
                watchlist_entries.append(movie)
    return render_template('results.html', title='Results', movies=movies, search_form=search_form, results_form=results_form, count=count, name=name, year=year, watchlist_entries=watchlist_entries)
Exemplo n.º 9
0
def profile(user_id):
    update_form = UpdateDetailsForm()
    if current_user.is_authenticated:
        if current_user.admin:
            user = User.query.filter_by(id=user_id).first()
            if update_form.validate_on_submit():
                user.forename = update_form.forename.data.strip()
                user.surname = update_form.surname.data.strip()
                if update_form.email.data.strip() != user.email:
                    other_user = User.query.filter_by(email=update_form.email.data).first()
                    if other_user:
                        flash('This email is in use, please use a different one!', 'danger')
                    else:
                        user.email = update_form.email.data.strip()
                        db.session.commit()
                        flash('Account details successfully updated!', 'success')
                else:
                    db.session.commit()
                    flash('Account details successfully updated!', 'success')
                return redirect(url_for('users.profile', user_id=user.id))
            elif request.method == 'GET':
                # Populate form with users current details
                update_form.forename.data = user.forename
                update_form.surname.data = user.surname
                update_form.email.data = user.email
        elif not current_user.admin:
            if update_form.validate_on_submit():
                current_user.forename = update_form.forename.data
                current_user.surname = update_form.surname.data
                current_user.email = update_form.email.data
                db.session.commit()
                flash('Account details successfully updated!', 'success')
                return redirect(url_for('users.profile', user_id=current_user.id))
            elif request.method == 'GET':
                # Populate form with users current details
                update_form.forename.data = current_user.forename
                update_form.surname.data = current_user.surname
                update_form.email.data = current_user.email
    else:
        abort(403)

    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    return render_template('profile.html', title='Profile', search_form=search_form, update_form=update_form)
Exemplo n.º 10
0
def register():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    if current_user.is_authenticated:
        flash('You are already logged in with a registered account!', 'danger')
        return redirect(url_for('movies.get_all_movies'))

    register_form = registrationForm()
    if register_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(register_form.password.data).decode('utf-8')
        user = User(forename=register_form.forename.data, surname=register_form.surname.data.strip(), email=register_form.email.data.strip(), password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Account successfully created. You can now log in!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register an account', register_form=register_form, search_form=search_form)
Exemplo n.º 11
0
def reset_token(token):
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    if current_user.is_authenticated:
        flash('You are already logged in with a registered account!', 'danger')
        return redirect(url_for('movies.get_all_movies'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('This is an invalid or expired token', 'danger')
        return redirect(url_for('users.request_reset'))
    password_reset_form = ResetPasswordForm()
    if password_reset_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(password_reset_form.password.data).decode('utf-8')
        user.password =  hashed_password
        db.session.commit()
        flash('Your password has been successfully updated. You can now log in!', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', title='Reset Password', search_form=search_form, password_reset_form=password_reset_form)
Exemplo n.º 12
0
def login():
    search_form = TitleSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))

    if current_user.is_authenticated:
        flash('You are already logged in with a registered account!', 'danger')
        return redirect(url_for('movies.get_all_movies'))
    else:
        login_form = loginForm()
        if login_form.validate_on_submit():
            user = User.query.filter_by(email=login_form.email.data).first()
            if user and bcrypt.check_password_hash(user.password, login_form.password.data): # check if both hashed passwords are equal
                login_user(user)
                # access page user was trying to access before login
                next_page = request.args.get('next')
                flash('Login successful!', 'success')
                return redirect(next_page) if next_page else redirect(url_for('movies.get_all_movies'))
            else:
                flash('Login unsuccessful, please check you have input the correct email and password!', 'danger')
    return render_template('login.html', title='Log in to your account', login_form=login_form, search_form=search_form)
Exemplo n.º 13
0
def search_for_movie(name, year):
    search_form = TitleSearchForm()
    results_form = ResultsSearchForm()
    if flask.request.method == 'POST' and search_form.validate_on_submit():
        return redirect(url_for('movies.title_results', name=search_form.movie_title.data.lower().strip()))
    elif flask.request.method == 'GET':
        watchlist_entry = None
        movie = Movie.query.filter(func.lower(Movie.title) == name.lower()).filter_by(year = year).first()
        if movie:
            if current_user.is_authenticated:
                watchlist_entry = WatchlistMovies.query.filter_by(userId=current_user.id, movieId=movie.movieId).first()
            return render_template('get_movie.html', title='Searched Movie', movie=movie, search_form=search_form, image=movie.movie_image, watchlist_entry=watchlist_entry)
        else:
            try:
                ttl, yr, imdb, imdb_votes, metacritic, metacritic_votes, synopsis, imdb_url, metacritic_url, tomatometer, tomatometer_votes, audience, audience_votes, rotten_tomatoes_url, letterboxd, letterboxd_votes, letterboxd_url, tmdb, tmdb_votes, image, tmdb_url, avg = get_all_ratings(name, year)
                movie = Movie(title=ttl, year=yr, imdb_rating=imdb, imdb_votes=imdb_votes, imdb_url=imdb_url, metascore=metacritic, metascore_votes=metacritic_votes, metacritic_url=metacritic_url, tomatometer=tomatometer,
                    tomatometer_votes=tomatometer_votes, audience_score=audience, audience_score_votes=audience_votes, rotten_tomatoes_url=rotten_tomatoes_url, letterboxd_rating=letterboxd, letterboxd_votes=letterboxd_votes,
                     letterboxd_url=letterboxd_url, tmdb_rating=tmdb, tmdb_votes=tmdb_votes, tmdb_url=tmdb_url, average_rating=avg, movie_image=image, synopsis=synopsis)
                db.session.add(movie)
                db.session.commit()
                return render_template('get_movie.html', title='Searched Movie', movie=movie, search_form=search_form, image=movie.movie_image)
            except Exception as e:
                db.session.rollback()
                return redirect(url_for('movies.title_results', name=name, year=year))