コード例 #1
0
def search_on_db():

    if request.method == "POST":
        return_ele = []

        value = request.form.get("search")
        popularity_element = Movies.select().where(
            Movies.popularity.contains(value)).execute()
        director_element = Movies.select().where(
            Movies.director.contains(value)).execute()
        genre_element = Movies.select().where(
            Movies.genre.contains(value)).execute()
        imdb_score_element = Movies.select().where(
            Movies.imdb_score.contains(value)).execute()
        name_element = Movies.select().where(
            Movies.name.contains(value)).execute()
        elements = [
            name_element, director_element, popularity_element, genre_element,
            imdb_score_element
        ]
        for ele in elements:
            for movie in ele:
                movie_element = str(movie.popularity), str(
                    movie.director), str(movie.genre), str(
                        movie.imdb_score), str(movie.name)
                return_ele.append(movie_element)

        if len(return_ele) > 0:
            return render_template("search_result.html",
                                   movies=list(set(return_ele)))
        else:
            msg = 'No Movies Found'
            return render_template('search_result.html', msg=msg)

    return render_template('search.html')
コード例 #2
0
def update_vote_average_count(id_movie, user_review, vote):
    vote = float(vote)
    get_vote = Movies.select(
        Movies.vote_average).where(Movies.id == id_movie).limit(1).get()
    get_average = Movies.select(
        Movies.vote_count).where(Movies.id == id_movie).limit(1).get()
    new_vote = ((get_vote.vote_average * get_average.vote_count) +
                1) / (get_average.vote_count + 1)
    updating_vote = Movies.update(vote_average=new_vote).where(
        Movies.id == id_movie)
    updating_vote.execute()
    Movies.update(vote_count=get_average.vote_count +
                  1).where(Movies.id == id_movie).execute()
    Reviews.create(review=user_review,
                   score=vote,
                   user_id=session['id'],
                   movie_id=id_movie)
    return 'Done'
コード例 #3
0
def dashboard():
    element = []
    for user in Movies.select():
        ele = str(user.popularity), str(user.director), str(user.genre), str(
            user.imdb_score), str(user.name), str(user.id)
        element.append(ele)

    if len(element) > 0:
        return render_template('dashboard.html', movies=element)
    else:
        msg = 'No Movies Found'
        return render_template('dashboard.html', msg=msg)
コード例 #4
0
ファイル: app.py プロジェクト: Harser/Flask
def index():
    # 10 randomly chosen movies
    movies = random.sample(list(Movies.select()), 10)
    return render_template('index.html', movies=movies)