Esempio n. 1
0
def ratings_create_quick(film_id):
    form = FilmRatingForm(request.form)
    r = Rating(form.score.data)

    r.user_id = current_user.id
    r.film_id = film_id

    db.session().add(r)
    db.session().commit()
    return redirect(url_for("films_show", film_id=film_id))
Esempio n. 2
0
def ratings_get_user_ratings():
    u = current_user
    ratings_count = Rating.get_count_of_ratings_user_has_done(u.id)
    user_ratings_average = Rating.user_ratings_average(u.id)
    if user_ratings_average == None:
        return render_template("ratings/user_ratings.html",
                               ratings=Rating.find_movies_user_has_rated(u.id),
                               ratings_count=ratings_count,
                               user_ratings_average=user_ratings_average)
    else:
        user_ratings_average = round(user_ratings_average, 2)
        return render_template("ratings/user_ratings.html",
                               ratings=Rating.find_movies_user_has_rated(u.id),
                               ratings_count=ratings_count,
                               user_ratings_average=user_ratings_average)
Esempio n. 3
0
def user_ratings_index():
    ratings = Rating.user_ratings(current_user.id)

    return render_template("ratings/personallist.html",
                           ratings=ratings,
                           sortby=None,
                           desc=None)
Esempio n. 4
0
def movies_get_movie(movie_id):
    m = Movie.query.get(movie_id)
    r = Rating.find_movie_avg(movie_id)
    r_count = Rating.get_count_of_ratings_in_movie(movie_id)
    credits = PersonsRoleInMovie.get_credits(movie_id)
    if r == None:
        return render_template("movies/movie.html",
                               movie=m,
                               form=MovieForm(),
                               rating=r,
                               rating_count=r_count,
                               credits=credits)
    else:
        r = round(r, 2)
        return render_template("movies/movie.html",
                               movie=m,
                               form=MovieForm(),
                               rating=r,
                               rating_count=r_count,
                               credits=credits)
Esempio n. 5
0
def ratings_create():
    form = RatingForm(request.form)
    form.beer.choices = [(g.id, g.name) for g in Beer.query.all()]
    form.flavor.choices = [(g.id, g.name) for g in Flavor.query.all()]

    if not form.validate():
        return render_template("ratings/new.html", form=form)

    r = Rating(form.rating.data, form.comment.data)
    r.account_id = current_user.id
    r.beer_id = form.beer.data

    db.session().add(r)
    db.session().commit()

    for g in form.flavor.data:
        rf = RatingFlavor(r.id, g)
        db.session().add(rf)
        db.session().commit()

    return redirect(url_for("ratings_index"))
Esempio n. 6
0
def welcome():
    films = Film.top_films()
    directors = Director.top_directors()
    actors = Actor.top_actors()
    recent_films = Film.recent_films()
    recent_reviews = Rating.recent_reviews()
    return render_template("index.html",
                           top_films=films,
                           top_directors=directors,
                           top_actors=actors,
                           recent_films=recent_films,
                           recent_reviews=recent_reviews)
Esempio n. 7
0
def ratings_create(route_id):
    form = RatingForm(request.form)
    if form.validate():
        rating = Rating.query.filter_by(account_id=current_user.id).filter_by(
            route_id=route_id).first()

        if rating is None:
            rating = Rating(int(form.new_rating.data), int(route_id))
            rating.account_id = current_user.id
            rating.set_rater_data(current_user.height, current_user.weight,
                                  current_user.arm_span)
            db.session().add(rating)
        else:
            rating._set_rating_value(int(form.new_rating.data))
            rating.set_rater_data(current_user.height, current_user.weight,
                                  current_user.arm_span)

        db.session().commit()

    return redirect(url_for("routes_index"))
Esempio n. 8
0
def user_ratings_sorted(sortby):
    ratings = Rating.user_ratings(current_user.id)
    desc = False
    if ('film' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[0])

    if ('score' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[4], reverse=True)

    if ('review' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[6])
    if ('desc' in sortby):
        ratings.reverse()
        desc = True
    return render_template("ratings/personallist.html",
                           ratings=ratings,
                           sortby=sortby,
                           desc=desc)
Esempio n. 9
0
def ratings_index_sorted(sortby):
    ratings = Rating.all_ratings_with_films_and_users()
    desc = False
    if ('film' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[0])
    if ('score' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[4], reverse=True)
    if ('user' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[2])
    if ('review' in sortby):
        ratings = sorted(ratings, key=lambda rating: rating[6])
    if ('desc' in sortby):
        ratings.reverse()
        desc = True
    return render_template("ratings/list.html",
                           ratings=ratings,
                           sortby=sortby,
                           desc=desc)
Esempio n. 10
0
def reviews_sorted(sortby):
    reviews = Rating.reviews()
    desc = False
    if ('film' in sortby):
        reviews = sorted(reviews, key=lambda rating: rating[0])

    if ('score' in sortby):
        reviews = sorted(reviews, key=lambda rating: rating[4], reverse=True)
    if ('user' in sortby):
        reviews = sorted(reviews, key=lambda rating: rating[2])
    if ('review' in sortby):
        reviews = sorted(reviews, key=lambda rating: rating[5])
    if ('desc' in sortby):
        reviews.reverse()
        desc = True
    return render_template("ratings/reviewlist.html",
                           reviews=reviews,
                           sortby=sortby,
                           desc=desc)
Esempio n. 11
0
def movies_view(movie_id):
    # Count the number of ratings for each category
    res = Rating.count_ratings_per_category(movie_id)

    # Assign the number of ratings to the correct category. Set the value to zero if there're no ratings.
    ratings = [0] * 10
    for result in res:
        ratings[result.get("rating") - 1] = result.get("count")
    # Find the category with the most ratings
    max_rating = max(max(ratings), 1)
    # Weight each category based on the highest number of ratings
    weighted_ratings = [r / max_rating for r in ratings]

    if current_user.is_authenticated:
        rating = Rating.query.filter_by(movie_id=movie_id,
                                        user_id=current_user.id).first()
    else:
        rating = None
    return render_template("movies/view.html",
                           movie=Movie.query.get(movie_id),
                           form=RatingForm(obj=rating),
                           rating=rating,
                           ratings=weighted_ratings)
Esempio n. 12
0
def update_wishlist(movie_id):
    rating = Rating.query.filter_by(movie_id=movie_id,
                                    user_id=current_user.id).first()

    if not rating:
        rating = Rating()
        rating.movie_id = movie_id
        rating.user_id = current_user.id
        db.session().add(rating)

    if request.form.get("wishlist"):
        rating.want_to_watch = True
    else:
        rating.want_to_watch = False

    db.session().commit()

    return redirect(url_for("movies_view", movie_id=movie_id))
Esempio n. 13
0
def movie_set_rating(movie_id):
    form = MovieRatingForm(request.form)

    s = Rating.check_if_user_has_rated_movie(current_user.id, movie_id)
    if not s:
        print("empty")
        u = current_user.id
        r = Rating(form.rating.data)
        r.account_id = current_user.id
        r.movie_id = movie_id
        db.session.add(r)
        db.session().commit()
    else:
        r = Rating.query.get(s[0])
        r.rating = form.rating.data
        db.session().commit()
    print(s)

    return redirect(url_for("movies_get_movie", movie_id=movie_id))
Esempio n. 14
0
def ratings_create():
    form = ReviewForm(request.form)
    r = Rating(form.score.data)

    r.user_id = current_user.id
    r.film_id = form.film.data
    r.title = form.title.data
    r.review = form.review.data
    if not form.validate() or form.film.data == None:
        ratings = Rating.query.all()
        films = Film.query.all()
        for r in ratings:
            if (r.user_id == current_user.id):
                for f in films:
                    if f.id == r.film_id:
                        films.remove(f)

        form.film.choices = [(f.id, f.name) for f in films]
        return render_template("ratings/new.html", form=form)
    db.session().add(r)
    db.session().commit()
    return redirect(url_for("reviews_index"))
Esempio n. 15
0
def add_rating(movie_id):
    rating = Rating.query.filter_by(movie_id=movie_id,
                                    user_id=current_user.id).first()

    form = RatingForm(request.form)
    if not form.validate():
        return render_template("movies/view.html",
                               movie=Movie.query.get(movie_id),
                               form=form,
                               rating=rating)

    if not rating:
        rating = Rating()
        rating.movie_id = movie_id
        rating.user_id = current_user.id
        rating.want_to_watch = False
        db.session().add(rating)

    rating.rating = form.rating.data

    db.session().commit()

    return redirect(url_for("movies_view", movie_id=movie_id))
Esempio n. 16
0
def reviews_index():
    reviews = Rating.reviews()
    return render_template("ratings/reviewlist.html",
                           reviews=reviews,
                           sortby=None,
                           desc=None)
Esempio n. 17
0
def ratings_index():
    ratings = Rating.all_ratings_with_films_and_users()
    return render_template("ratings/list.html",
                           ratings=ratings,
                           sortby=None,
                           desc=None)