Пример #1
0
def show_movie(movie_id):
    cur_movie = model.get_movie(movie_id)
    ratings = cur_movie.ratings

    rating_nums = []
    user_rating = None
    user = model.get_user_by_email(session["email"])
    
    for r in ratings:
        if r.user_id == user.id:
            user_rating = r
        rating_nums.append(r.rating)
    avg_rating = float(sum(rating_nums))/len(rating_nums)

    # Prediction code: only predict if the user hasn't rated it.

    prediction = None
    if not user_rating:
        prediction = user.predict_rating(cur_movie)
    # End prediction


    if session.get("email"):
        email = True
    else:
        email = False
    # return render_template("movie.html", movie=cur_movie, ratings=ratings,email=email)
    return render_template("movie.html", movie=cur_movie, ratings=ratings,
     avg_rating=avg_rating, email=email, prediction=prediction)
Пример #2
0
def show_movie(movie_id):
    cur_movie = model.get_movie(movie_id)
    ratings = model.get_ratings_by_movie_id(movie_id)

    if session.get("email"):
        email = True
    else:
        email = False

    return render_template("movie.html", movie=cur_movie, ratings=ratings, email=email)
Пример #3
0
def review_movie(movie_id):
    print "#"*80 
    user = model.get_user_id_by_email(session.get("email"))
    print user
    print "#"*80
    user_id = user.id
    movie_rating = request.form.get("ratings")

    model.add_movie_rating(user_id=user_id, movie_id=movie_id, rating=movie_rating)

    cur_movie = model.get_movie(movie_id)
    ratings = model.get_ratings_by_movie_id(movie_id)

    email = True
    
    return render_template("movie.html", movie=cur_movie, ratings=ratings, email=email)
Пример #4
0
def show_movie(movie_id):
    ratings = model.get_ratings_for_movie(movie_id)
    movie_object = model.get_movie(movie_id)

    all_sum = 0
    count = 0
    for rating in ratings:
        all_sum += rating.rating
        count += 1

    avg = float(all_sum)/count

    avg = model.rounding(avg)

    rated = model.get_rating_movie_user(session['user_id'], movie_id)

    return render_template("movie.html", avg=avg, movie_object=movie_object, rated=rated)
Пример #5
0
 def GET(self, id):
     """ View single movie """
     movie = model.get_movie(int(id))
     reviews = model.get_reviews(int(id))
     form = Review.form()
     return render.view(movie, form, reviews)