Esempio n. 1
0
def collect_add(movie_id):
    count = MovieCollect.query.filter_by(user_id=session.get("user_id"),
                                         movie_id=movie_id).count()
    if count:
        return jsonify(statuc="400", message="failed")
    col = MovieCollect(user_id=session.get("user_id"), movie_id=movie_id)
    db.session.add(col)
    db.session.commit()
    return jsonify(status="200", message="succeed")
Esempio n. 2
0
def add_moviecollect():
    movie_id = request.args.get('movie_id', '')
    user_id = request.args.get('user_id', '')
    movie_collect = MovieCollect.query.filter_by(user_id=int(user_id),
                                                 movie_id=int(movie_id))
    if movie_collect.count() == 1:
        data = dict(ok=0)
    if movie_collect.count() == 0:
        movie_collect = MovieCollect(user_id=int(user_id),
                                     movie_id=int(movie_id))
        db.session.add(movie_collect)
        db.session.commit()
        data = dict(ok=1)
    import json
    return json.dumps(data)
Esempio n. 3
0
def add_moviecollect():
    movie_id = request.args.get('movie_id', '')
    user_id = request.args.get('user_id', '')
    # 判断某用户是否收藏该电影
    collectCount = MovieCollect.query.filter_by(user_id=user_id,
                                                movie_id=movie_id).count()
    # 如果已经收藏, 则返回ok=0
    if collectCount == 1:
        data = dict(ok=0)
    # 如果没有收藏, 添加收藏到数据库中, 并且返回ok=1
    else:
        moviecollect = MovieCollect(user_id=user_id, movie_id=movie_id)
        db.session.add(moviecollect)
        db.session.commit()
        data = dict(ok=1)
    # 因为数据要传给前端的Ajax, 所有必须转成json格式;
    import json
    return json.dumps(data)
Esempio n. 4
0
def add_moviecollect():
    movie_id = request.args.get('movie_id', '')
    user_id = request.args.get('user_id', '')
    movie_collect = MovieCollect.query.filter_by(user_id=int(user_id),
                                                 movie_id=int(movie_id))
    # 如果用户已经收藏, 则返回OK=0;
    if movie_collect.count() == 1:
        data = dict(ok=0)
    # 如果用户未收藏, 则返回OK=1;
    elif movie_collect.count() == 0:
        movie_collect = MovieCollect(user_id=int(user_id),
                                     movie_id=int(movie_id))
        db.session.add(movie_collect)
        db.session.commit()
        data = dict(ok=1)
    else:
        data = dict(ok='error')
    import json
    return json.dumps(data)
Esempio n. 5
0
 def generate_movie_collect():
     return MovieCollect(
         movie_id=movie.id,
         user_id=users[randint(1, 10)].id,
     )