Exemplo n.º 1
0
def new_rating():
    error = None
    #retrieves form information
    new_movie = request.form["new_movie"]
    new_rating = request.form["new_rating"]

    #test if new_rating is between 1-5

    # test if the movie exists in db
    movie_exists = model.session.query(
        model.Movies).filter_by(movie_title=new_movie).first()

    # movie_exists = model.session.query(model.Ratings).filer(Ratings.movie_title.like('%new_movie%')).first()

    if movie_exists:
        movie_id = movie_exists.id
        release_date = movie_exists.release_date
        video_release_date = movie_exists.video_release_date
        now = datetime.datetime.now()
        imdb_url = movie_exists.imdb_url

        new_rating_item = model.Ratings(user_id=fsession["user_id"],
                                        movie_id=movie_id,
                                        rating=new_rating,
                                        timestamp=now)

        model.session.add(new_rating_item)
        model.session.commit()
        return redirect("/view_user")

    else:
        # make a new PAGE so you can make new movie
        return redirect("/new_movie")
Exemplo n.º 2
0
def rate_movie(movie_id):
    print "rating movie"
    rating = request.form.get("ratingRadio")
    if rating:
        new_rating = model.Ratings(movie_id = movie_id, user_id = session.get("user_id"), timestamp = datetime.datetime.now(), rating = rating)
        model.add_rating(new_rating) #add + commit

        flash("Your rating has been recorded!")
    else:
        flash("Please choose a rating!")
    return redirect(url_for("view_movie", movie_id = movie_id))
Exemplo n.º 3
0
def load_ratings(session):
    ### FROM FILE user id | item id | rating | timestamp
    ### PASS INTO id, user_id, movie_id, rating, timestamp
    data = csv_reader("seed_data/u.data", "\t")
    for row in data:
        user_id = int(row[0])
        item_id = int(row[1])
        rating = int(row[2])
        timestamp = row[3]
        timestamp = datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d')
        timestamp =  datetime.strptime(timestamp, '%Y-%m-%d')
        #timestamp = datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d')
        rating = model.Ratings(user_id=user_id, movie_id=item_id, rating=rating, timestamp=timestamp)
        session.add(rating)
    session.commit()
Exemplo n.º 4
0
def load_ratings(session):
    # use u.data
    with open("seed_data/u.data", 'rb') as csvfile:
        csvreader = csv.reader(csvfile, delimiter="\t")
        for row in csvreader:
            user_id = row[0]
            movie_id = row[1]
            rating = row[2]
            if len(row[3]) > 0:
                timestamp = datetime.datetime.fromtimestamp(float(row[3]))
            else:
                timestamp = None
            new_rating = model.Ratings(user_id=user_id,
                                       movie_id=movie_id,
                                       rating=rating,
                                       timestamp=timestamp)
            session.add(new_rating)
Exemplo n.º 5
0
def add_movie():
    # TAKE ALL THE FORM INFO
    error = None
    #retrieves form information
    new_title = request.form["new_title"]
    movie_release = request.form["movie_release"]

    movie_release = datetime.datetime.strptime(
        movie_release, "%Y")  # format: 1962-01-01 00:00:00

    video_release = request.form["video_release"]
    imdb_url = request.form["imdb_url"]
    rating = request.form["rating"]

    if video_release == '':
        video_release = None

    # make a new movie item
    new_movie_item = model.Movies(movie_title=new_title,
                                  release_date=movie_release,
                                  video_release_date=video_release,
                                  imdb_url=imdb_url)

    model.session.add(new_movie_item)
    model.session.commit()

    # query id for that movie item
    query = model.session.query(
        model.Movies).filter_by(movie_title=new_title).first()

    # make a new rating with the user id from the session
    now = datetime.datetime.now()
    query_id = query.id
    new_rating_item = model.Ratings(user_id=fsession["user_id"],
                                    movie_id=query_id,
                                    rating=rating,
                                    timestamp=now)

    #test if new_rating is between 1-5

    # test if the movie exists in db

    model.session.add(new_rating_item)
    model.session.commit()
    return redirect("/view_user")