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
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)
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
def cancel_like(): form = LikeForm().validate_for_api() Like.cancel(form.art_id.data, form.type.data) return Success()
def add_like(): form = LikeForm().validate_for_api() Like.add_favor(form.art_id.data, form.type.data) return Success()
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='取消点赞成功')
def get_count(): member = get_current_member() count = Like.get_like_count_by_member(member.id) return {'member_id': member.id, 'like_count': count}
def get_info(pid): member = get_current_member() info = Like.get_like(pid, member.id) return info
def like_cancel(pid): member = get_current_member() Like.unlike(pid, member.id) return Success(msg='取消点赞成功')
def like(pid): member = get_current_member() Like.like(pid, member.id) return Success(msg='点赞成功')
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')
def get_like(type, id): member_id = get_current_member().id like = Like.get_like(type, id, member_id) return jsonify(like)
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)
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})