Пример #1
0
 def get(self,post_id):
     post = backend.get_post(post_id)
     curr_user = backend.get_user_by_uid(g.ukey)
     post['is_like'] = backend.is_like_post(curr_user['id'],post['id'])
     post['like_count'] = backend.get_post_liked_count(post_id)
     post['comment_count'] = backend.get_post_comment_count(post_id)
     return jsonify(**post)
Пример #2
0
 def get(self, post_id):
     post = backend.get_post(post_id)
     curr_user = backend.get_user_by_uid(g.ukey)
     post["is_like"] = backend.is_like_post(curr_user["id"], post["id"])
     post["like_count"] = backend.get_post_liked_count(post_id)
     post["comment_count"] = backend.get_post_comment_count(post_id)
     return jsonify(**post)
Пример #3
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)
Пример #4
0
    def test_is_like_post(self):
        user1 = backend.add_user('username1','photo_url','weibo_id1')
        post1 = backend.add_post('title1',user1['id'],'video_url',
                    pic_small='pic_small')
        post2 = backend.add_post('title2',user1['id'],'video_url',
                    pic_small='pic_small')

        backend.add_like(user1['id'],post1['id'])
        backend.add_like(user1['id'],post2['id'])

        ret = backend.is_like_post(user1['id'],[post1['id'],post2['id']])
        assert ret[post1['id']] == True
Пример #5
0
    def test_is_like_post(self):
        user1 = backend.add_user('username1', 'photo_url', 'weibo_id1')
        post1 = backend.add_post('title1',
                                 user1['id'],
                                 'video_url',
                                 pic_small='pic_small')
        post2 = backend.add_post('title2',
                                 user1['id'],
                                 'video_url',
                                 pic_small='pic_small')

        backend.add_like(user1['id'], post1['id'])
        backend.add_like(user1['id'], post2['id'])

        ret = backend.is_like_post(user1['id'], [post1['id'], post2['id']])
        assert ret[post1['id']] == True
Пример #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)
Пример #7
0
    def get(self,user_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

        limit = 10
        offset = (page-1) * limit
        
        feeds = backend.get_latest_feed(user_id,limit,offset)

        if len(feeds) > 0:
            feeds = pipe_load(feeds)   
        
        curr_user = backend.get_user_by_uid(g.ukey)
        liked_post_ids = [p['id'] for p in feeds]
        liked_dict = backend.is_like_post(curr_user['id'],liked_post_ids)
        for up in feeds:
            up['is_like'] = liked_dict.get(up['id']) or False

        if page == 1:
            redis.hset(FEED_UPDATE_TIME_KEY % {'user_id':user_id},
                                'last_update_time',int(time.time()))
        return jsonify(results=feeds,page=page)
Пример #8
0
    def get(self, user_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

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

        feeds = backend.get_latest_feed(user_id, limit, offset)

        if len(feeds) > 0:
            feeds = pipe_load(feeds)

        curr_user = backend.get_user_by_uid(g.ukey)
        liked_post_ids = [p['id'] for p in feeds]
        liked_dict = backend.is_like_post(curr_user['id'], liked_post_ids)
        for up in feeds:
            up['is_like'] = liked_dict.get(up['id']) or False

        if page == 1:
            redis.hset(FEED_UPDATE_TIME_KEY % {'user_id': user_id},
                       'last_update_time', int(time.time()))
        return jsonify(results=feeds, page=page)