示例#1
0
    def action(self):
        """操作:点赞或取消"""

        if self.like:
            self.action_code = 2
            db.session.delete(self.like)
        else:
            self.action_code = 1
            self.like = Like()
            self.like.like_type = self.like_type
            self.like.uid = self.uid
            self.like.nickname = self.nickname
            self.like.avatar = self.avatar
            self.like.ttype = self.ttype
            self.like.tid = self.tid
            self.like.tname = self.tname
            self.like.timg = self.timg
            self.like.ext_data = self.ext_data
            self.like.add_time = self.current_time
            db.session.add(self.like)

        # 更新第三方冗余数据
        self._update_third()

        return True
示例#2
0
def get_like_products():
    member = get_current_member()
    start, count = paginate()
    res = Like.get_like_products(member.id, start, count, throw=True)
    for model in res['models']:
        model._fields = [
            'id', 'name', 'old_price_str', 'price_str', 'summary', 'image'
        ]
    return jsonify(res)
示例#3
0
    def like(self, post):
        '''Like or Unlike the post.
        User can only like one time. The next time this function is called,
        it unlikes the Post
        '''

        # The owner of the post cannot like his own post
        if self.user.key() != post.user.key():
            # Check if the user already has liked the post
            mylike = post.likes.filter('user ='******'/post/%s' % str(post.key().id()))
        return
示例#4
0
def cancel_like():
    form = LikeForm().validate_for_api()
    Like.cancel(form.art_id.data, form.type.data)
    return Success()
示例#5
0
def add_like():
    form = LikeForm().validate_for_api()
    Like.add_favor(form.art_id.data, form.type.data)
    return Success()
示例#6
0
def unlike():
    form = LikeForm().validate_for_api()
    member_id = get_current_member().id
    Like.unlike(form.type.data, form.art_id.data, member_id)
    return Success(msg='取消点赞成功')
示例#7
0
def get_count():
    member = get_current_member()
    count = Like.get_like_count_by_member(member.id)
    return {'member_id': member.id, 'like_count': count}
示例#8
0
def get_info(pid):
    member = get_current_member()
    info = Like.get_like(pid, member.id)
    return info
示例#9
0
def like_cancel(pid):
    member = get_current_member()
    Like.unlike(pid, member.id)
    return Success(msg='取消点赞成功')
示例#10
0
def like(pid):
    member = get_current_member()
    Like.like(pid, member.id)
    return Success(msg='点赞成功')
示例#11
0
def classic_with_like_status(classic):
    like_status = Like.get_like_status_by_member(get_current_member().id,
                                                 classic.type, classic.id)
    classic.like_status = like_status
    classic._fields.append('like_status')
示例#12
0
def get_like(type, id):
    member_id = get_current_member().id
    like = Like.get_like(type, id, member_id)
    return jsonify(like)
示例#13
0
def get_favor(book_id):
    member_id = get_current_member().id
    like = Like.get_like(ClassicType.BOOK.value, book_id, member_id)
    return jsonify(like)
示例#14
0
def get_favor_count():
    member_id = get_current_member().id
    fav_nums = Like.get_like_count_by_member_type(member_id,
                                                  ClassicType.BOOK.value)
    return jsonify({'count': fav_nums})