Example #1
0
    def get(self,user_id):
        try:
            page = int(request.values.get('page','1'))
        except:
            page = 1

        limit = 20
        offset = (page-1) * limit
        
        curr_user = backend.get_user_by_uid(g.ukey)
        user_posts = backend.get_user_post(user_id,limit=limit,offset=offset)

        liked_post_ids = [p['id'] for p in user_posts];
        liked_dict = backend.is_like_post(curr_user['id'],liked_post_ids)
        for up in user_posts:
            up['is_like'] = liked_dict.get(up['id']) or False
            up['like_count'] = backend.get_post_liked_count(up['id'])
            up['comment_count'] = backend.get_post_comment_count(up['id'])
        


        count = backend.get_user_post_count(user_id)
        total_page = (count + limit - 1) / limit

        return jsonify(posts=user_posts,page=page,total_page=total_page)
Example #2
0
    def test_get_user_post(self):
        user = backend.add_user('username','photo_url','weibo_id')
        post1 = backend.add_post('title1',user['id'],'video_url',
                    pic_small='pic_small')
        post2 = backend.add_post('title2',user['id'],'video_url',
                    pic_small='pic_small')
        
        posts = backend.get_user_post(user['id'])
        assert len(posts) == 2

        count = backend.get_user_post_count(user['id'])
        assert count == 2
Example #3
0
    def test_get_user_post(self):
        user = backend.add_user('username', 'photo_url', 'weibo_id')
        post1 = backend.add_post('title1',
                                 user['id'],
                                 'video_url',
                                 pic_small='pic_small')
        post2 = backend.add_post('title2',
                                 user['id'],
                                 'video_url',
                                 pic_small='pic_small')

        posts = backend.get_user_post(user['id'])
        assert len(posts) == 2

        count = backend.get_user_post_count(user['id'])
        assert count == 2
Example #4
0
    def get(self, user_id):
        user = backend.get_user(user_id)

        user_following_count = backend.get_user_following_count(user_id)
        user_follower_count = backend.get_user_follower_count(user_id)
        user_post_count = backend.get_user_post_count(user_id)
        user_liked_post_count = backend.get_user_liked_post_count(user_id)

        curr_user = backend.get_user_by_uid(g.ukey)

        is_follow = backend.is_following_user(curr_user['id'], user_id)

        pd = {
            'is_follow': is_follow,
            'following_count': user_following_count,
            'follower_count': user_follower_count,
            'post_count': user_post_count,
            'liked_post_count': user_liked_post_count
        }
        user.update(pd)
        return jsonify(**user)
Example #5
0
    def get(self,user_id):
        user = backend.get_user(user_id)

        user_following_count = backend.get_user_following_count(user_id)
        user_follower_count = backend.get_user_follower_count(user_id)
        user_post_count = backend.get_user_post_count(user_id)
        user_liked_post_count = backend.get_user_liked_post_count(user_id)

        curr_user = backend.get_user_by_uid(g.ukey)

        is_follow = backend.is_following_user(curr_user['id'],user_id)
        
        pd = {
                'is_follow':is_follow,
                'following_count':user_following_count,
                'follower_count':user_follower_count,
                'post_count':user_post_count,
                'liked_post_count':user_liked_post_count
                }
        user.update(pd)
        return jsonify(**user)
Example #6
0
    def get(self, user_id):
        try:
            page = int(request.values.get("page", "1"))
        except:
            page = 1

        limit = 20
        offset = (page - 1) * limit

        curr_user = backend.get_user_by_uid(g.ukey)
        user_posts = backend.get_user_post(user_id, limit=limit, offset=offset)

        liked_post_ids = [p["id"] for p in user_posts]
        liked_dict = backend.is_like_post(curr_user["id"], liked_post_ids)
        for up in user_posts:
            up["is_like"] = liked_dict.get(up["id"]) or False
            up["like_count"] = backend.get_post_liked_count(up["id"])
            up["comment_count"] = backend.get_post_comment_count(up["id"])

        count = backend.get_user_post_count(user_id)
        total_page = (count + limit - 1) / limit

        return jsonify(posts=user_posts, page=page, total_page=total_page)