예제 #1
0
파일: post.py 프로젝트: gitthinkoo/motiky
 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 test_get_post(self):
        user = backend.add_user('username','photo_url','weibo_id')
        post = Post(title='title',author_id=user['id'],pic_small='pic_small')
        db.session.add(post)
        db.session.commit()

        _post = backend.get_post(post.id)
        assert _post['title'] == 'title'
예제 #4
0
    def test_get_post(self):
        user = backend.add_user('username', 'photo_url', 'weibo_id')
        post = Post(title='title', author_id=user['id'], pic_small='pic_small')
        db.session.add(post)
        db.session.commit()

        _post = backend.get_post(post.id)
        assert _post['title'] == 'title'
예제 #5
0
 def delete(self,post_id):
     post = backend.get_post(post_id)
     curr_id = authutil.get_user_id(g.ukey)
     if post['author_id'] != curr_id:
         return jsonify(error='forbid')
     try:
         backend.set_post(post_id,{'show':'deleted_by_user'})
     except BackendError,ex:
         abort(501)
예제 #6
0
파일: post.py 프로젝트: gitthinkoo/motiky
 def delete(self, post_id):
     post = backend.get_post(post_id)
     curr_id = authutil.get_user_id(g.ukey)
     if post["author_id"] != curr_id:
         return jsonify(error="forbid")
     try:
         backend.set_post(post_id, {"show": "deleted_by_user"})
     except BackendError, ex:
         abort(501)
예제 #7
0
    def post(self):
        data = NewCommentSchema().deserialize(request.json)

        user = backend.get_user(data['author_id'])

        post = backend.get_post(data['post_id'])

        if user['uid'] != g.ukey:
            return jsonify(error='not the user')

        try:
            comment = backend.add_comment(data['post_id'],
                                          data['content'].encode('utf-8'),
                                          data['author_id'])
        except BackendError, ex:
            raise
예제 #8
0
파일: comment.py 프로젝트: Letbeauty/motiky
    def post(self):
        data = NewCommentSchema().deserialize(request.json)
        
        user = backend.get_user(data['author_id'])

        post = backend.get_post(data['post_id'])

        if user['uid'] != g.ukey:
            return jsonify(error='not the user')
        
        try:
            comment = backend.add_comment(
                    data['post_id'],
                    data['content'].encode('utf-8'),
                    data['author_id']
                    )
        except BackendError,ex:
            raise
예제 #9
0
class PostLikeView(MethodView):

    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