示例#1
0
 def is_following(cls, follower_id, followee_id):
     entry = db.query(
         cls.model).filter(Follower.follower_id == follower_id,
                           Follower.followee_id == followee_id).first()
     if entry:
         return True
     return False
示例#2
0
def login():
    request_data = request.json
    username = request_data.get('username')
    password = request_data.get('password')
    user = db.query(User).filter(User.username == username).first()
    if user is None or not check_encrypted_password(password, user.password):
        raise NotFound("User not found with the entered credentials")
    token = encode_auth_token(user.username, Entity.USER.value)
    return jsonify({"auth_token": token}), 200
示例#3
0
def feed():
    auth_token = request.headers.get('access_token')
    current_user = generate_user_from_auth_token(auth_token)
    #  HIT REDIS FOR ALL POSTS RELATED TO
    followees = FollowerMethods.get_followees(current_user.id)
    posts = []
    for followee in followees:
        user = UserMethods.get_record_with_id(followee.followee_id)
        start_time = datetime.utcnow()
        user_posts = db.query(Post).filter(Post.user_id == user.id).all()
        print(datetime.utcnow() - start_time)
        for post in user_posts:
            posts.append(
                dict(caption=post.caption,
                     image=post.image._public_url,
                     user_id=post.user_id))
    return jsonify({"posts": posts})
示例#4
0
 def remove_request(cls, follower_id, followee_id):
     db.query(
         cls.model).filter(cls.model.followee_id == followee_id,
                           cls.model.follower_id == follower_id).delete()
示例#5
0
 def get_follow_requests(cls, followee_id):
     return db.query(
         cls.model).filter(cls.model.followee_id == followee_id).all()
示例#6
0
 def get_followees(cls, user_id):
     return db.query(
         cls.model).filter(Follower.follower_id == user_id).all()
示例#7
0
 def unfollow(cls, follower_id, followee_id):
     db.query(
         cls.model).filter(cls.model.follower_id == follower_id,
                           cls.model.followee_id == followee_id).delete()
示例#8
0
 def delete_record(cls, photo_id, user_id):
     try:
         db.query(cls.model).filter(cls.model.photo_id == photo_id,
                                    cls.model.user_id == user_id).delete()
     except Exception:
         raise BadRequest('Like cannot be deleted')
示例#9
0
 def get_latest_public_posts(cls, page):
     page = int(page)
     # gives 10 results as default is 10 in paginate method
     return db.query(Post).order_by(Post.created.desc()).paginate(
         page=page, per_page=int(app.config.get('MAX_POSTS_PER_PAGE')))
示例#10
0
 def get_user_by_username(cls, username):
     return db.query(cls.model).filter_by(username=username).first()
示例#11
0
 def get_record_with_id(cls, model_id):
     return db.query(cls.model).filter(cls.model.id == model_id).first()
示例#12
0
 def get_all_records(cls, limit=100):
     query = db.query(cls.model).order_by(cls.model.id.desc())
     return query.all() if limit == 0 else query.limit(limit)