Esempio n. 1
0
def collect(pid):
    # 判断是否收藏
    if current_user.is_favorite(pid):
        current_user.del_favorite(pid)
    else:
        current_user.add_favorite(pid)
    favorite_count = Posts.query.get(pid).users.count()
    return jsonify({'result': 'ok', 'data': favorite_count, 'pid': pid})
Esempio n. 2
0
def collect(pid):
    if current_user.is_favorite(pid):
        #取消收藏
        current_user.del_favorite(pid)
    else:
        #添加收藏
        current_user.add_favorite(pid)
    return jsonify({'result':'ok'})
Esempio n. 3
0
def collect(pid):
    # 判断是否收藏
    if current_user.is_favorite(pid):
        # 取消收藏
        current_user.del_favorite(pid)
        return jsonify({'status': '收藏'})
    else:
        current_user.add_favorite(pid)
    return jsonify({'status': '取消收藏'})
Esempio n. 4
0
def collect(pid):
    #判断是否已经收藏
    if current_user.is_favorite(pid):
        current_user.del_favorite(pid)
        status = '收藏'
    else:
        current_user.add_favorite(pid)
        status = '取消收藏'
    return jsonify({'status': status})
Esempio n. 5
0
def del_favorite(id):
    '''取消收藏'''
    post = Post.query.filter_by(id=id).first()
    if post is None:
        flash(_('Invalid post.'), 'danger')
        return redirect(url_for('.index'))
    if not current_user.is_favorite(post):
        flash(_('You are not favorite this post.'), 'warning')
        return redirect(url_for('.user', username=current_user.username))
    current_user.del_favorite(post)
    flash(_('You are not favorite <%(post)s> anymore.', post=post.title),
          'success')
    return redirect(url_for('.user', username=current_user.username))