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)
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)
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)
def pipe_load(feeds): # todo some pipe load feeds_ret = [] for po in feeds: try: user = backend.get_user(po['author_id']) po['user'] = user po['like_count'] = backend.get_post_liked_count(po['id']) po['comment_count'] = backend.get_post_comment_count(po['id']) except BackendError,ex: continue
def pipe_load(feeds): # todo some pipe load feeds_ret = [] for po in feeds: try: user = backend.get_user(po['author_id']) po['user'] = user po['like_count'] = backend.get_post_liked_count(po['id']) po['comment_count'] = backend.get_post_comment_count(po['id']) except BackendError, ex: continue
def get(self): try: page = int(request.values.get('page','1')) except: page = 1 limit = 20 offset = (page-1)*limit posts = backend.get_latest_post(limit=limit,offset=offset) count = backend.get_post_count() for post in posts: post['like_count'] = backend.get_post_liked_count(post['id']) post['comment_count'] = backend.get_post_comment_count(post['id']) total_page = (count + limit -1 ) / limit return jsonify(posts=posts,page=page,total_page=total_page)
def get(self): try: page = int(request.values.get("page", "1")) except: page = 1 limit = 20 offset = (page - 1) * limit posts = backend.get_latest_post(limit=limit, offset=offset) count = backend.get_post_count() for post in posts: post["like_count"] = backend.get_post_liked_count(post["id"]) post["comment_count"] = backend.get_post_comment_count(post["id"]) total_page = (count + limit - 1) / limit return jsonify(posts=posts, page=page, total_page=total_page)
def get(self,post_id): try: page = int(request.values.get('page','1')) except: page = 1 limit = 20 offset = (page-1)*limit comments = backend.get_post_comment(post_id, limit=limit,offset=offset) for comment in comments: user = backend.get_user(comment['author_id']) comment['user'] = user count = backend.get_post_comment_count(post_id) total_page = (count + limit -1 ) / limit return jsonify(comments=comments,page=page,total_page=total_page)
def get(self, user_id): try: page = int(request.values.get("page")) except: page = 1 limit = 20 offset = (page - 1) * limit liked_posts = backend.get_user_liked_post(user_id, limit=limit, offset=offset) for p in liked_posts: p["is_like"] = True p["like_count"] = backend.get_post_liked_count(p["id"]) p["comment_count"] = backend.get_post_comment_count(p["id"]) count = backend.get_user_liked_post_count(user_id) total_page = (count + limit - 1) / limit return jsonify(posts=liked_posts, page=page, total_page=total_page)
def get(self,user_id): try: page = int(request.values.get('page')) except: page = 1 limit = 20 offset = (page-1) * limit liked_posts = backend.get_user_liked_post(user_id,limit=limit,offset=offset) for p in liked_posts: p['is_like'] = True p['like_count'] = backend.get_post_liked_count(p['id']) p['comment_count'] = backend.get_post_comment_count(p['id']) count = backend.get_user_liked_post_count(user_id) total_page = (count + limit -1) / limit return jsonify(posts=liked_posts,page=page,total_page=total_page)
def test_comment(self): user1 = backend.add_user('username1','photo_url','weibo_id1') user2 = backend.add_user('username2','photo_url','weibo_id2') 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') comment1 = backend.add_comment(post1['id'],'comment1',user2['id']) assert comment1['post_id'] == post1['id'] comment2 = backend.add_comment(post1['id'],'comment2',user2['id']) comments = backend.get_post_comment(post1['id']) assert len(comments) == 2 ret = backend.get_post_comment_count(post1['id']) assert ret == 2
def get(self, post_id): try: page = int(request.values.get('page', '1')) except: page = 1 limit = 20 offset = (page - 1) * limit comments = backend.get_post_comment(post_id, limit=limit, offset=offset) for comment in comments: user = backend.get_user(comment['author_id']) comment['user'] = user count = backend.get_post_comment_count(post_id) total_page = (count + limit - 1) / limit return jsonify(comments=comments, page=page, total_page=total_page)
def test_comment(self): user1 = backend.add_user('username1', 'photo_url', 'weibo_id1') user2 = backend.add_user('username2', 'photo_url', 'weibo_id2') 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') comment1 = backend.add_comment(post1['id'], 'comment1', user2['id']) assert comment1['post_id'] == post1['id'] comment2 = backend.add_comment(post1['id'], 'comment2', user2['id']) comments = backend.get_post_comment(post1['id']) assert len(comments) == 2 ret = backend.get_post_comment_count(post1['id']) assert ret == 2
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)