Beispiel #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)
Beispiel #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)
Beispiel #3
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)
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
class PostUnlikeView(MethodView):

    def post(self):
        data = PostUnlikeSchema().deserialize(request.json)
        try:
            ret = backend.del_like(data['user_id'],data['post_id'])
        except BackendError,ex:
            raise 

        liked_count = backend.get_post_liked_count(data['post_id'])

        return jsonify(like_count=liked_count)
Beispiel #7
0
    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)
Beispiel #8
0
    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)
Beispiel #9
0
    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)
Beispiel #10
0
    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)
Beispiel #11
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)
Beispiel #12
0
            ret = backend.add_like(data['user_id'],data['post_id'])
        except BackendError,ex:
            return jsonify(error='can not add like')

        try:
            post = backend.get_post(data['post_id'])
            backend.add_activity({
                    'post_id':data['post_id'],
                    'from_id':data['user_id'],
                    'to_id':post['author_id'],
                    'atype':'like'
                })
        except BackendError,ex:
            pass

        liked_count = backend.get_post_liked_count(data['post_id'])

        return jsonify(like_count=liked_count)

class PostUnlikeView(MethodView):

    def post(self):
        data = PostUnlikeSchema().deserialize(request.json)
        try:
            ret = backend.del_like(data['user_id'],data['post_id'])
        except BackendError,ex:
            raise 

        liked_count = backend.get_post_liked_count(data['post_id'])

        return jsonify(like_count=liked_count)
Beispiel #13
0
    def post(self):
        data = PostLikeSchema().deserialize(request.json)
        try:
            ret = backend.add_like(data["user_id"], data["post_id"])
        except BackendError, ex:
            return jsonify(error="can not add like")

        try:
            post = backend.get_post(data["post_id"])
            backend.add_activity(
                {"post_id": data["post_id"], "from_id": data["user_id"], "to_id": post["author_id"], "atype": "like"}
            )
        except BackendError, ex:
            pass

        liked_count = backend.get_post_liked_count(data["post_id"])

        return jsonify(like_count=liked_count)


class PostUnlikeView(MethodView):
    def post(self):
        data = PostUnlikeSchema().deserialize(request.json)
        try:
            ret = backend.del_like(data["user_id"], data["post_id"])
        except BackendError, ex:
            raise

        liked_count = backend.get_post_liked_count(data["post_id"])

        return jsonify(like_count=liked_count)