Ejemplo n.º 1
0
def collections(pid):
    try:
        if current_user.is_favorite(pid):
            current_user.remove_favorite(pid)
        else:
            current_user.add_favorite(pid)
        return jsonify({'res': 200})
    except:
        return jsonify({'res': 401})
Ejemplo n.º 2
0
def doFavorite():
    try:
        pid = int(request.args.get('pid'))
        if current_user.is_favorite(pid):
            current_user.remove_favorite(pid)
        else:
            current_user.add_favorite(pid)
        return jsonify({'code': 200})
    except:
        return jsonify({'code': 500})
Ejemplo n.º 3
0
def collections():
    try:
        pid = int(request.args.get('pid'))
        if pid and current_user.is_favorite(pid):
            current_user.remove_favorite(pid)
            flash('取消收藏成功!')
            # return redirect(url_for('center.collections'))
    except:
        pass
    data = current_user.favorites.all()  # 查询所有的收藏
    return render_template('owncenter/collections.html',data=data)
Ejemplo n.º 4
0
def favorite(pid):
    try:
        if current_user.is_favorite(pid):
            print('取消收藏')
            current_user.remove_favorite(pid)
        else:
            print('添加收藏')
            current_user.add_favorite(pid)
        return jsonify({'res': 200})
    except:
        return jsonify({'res': 500})
Ejemplo n.º 5
0
def favorite(pid):
    # 如果收藏了  就清除缓存
    cache.clear()
    try:
        if current_user.is_favorite(pid):
            current_user.remove_favorite(pid)
        else:
            current_user.add_favorite(pid)
        return jsonify({'stat': 200})
    except:
        return jsonify({'stat': 500})
Ejemplo n.º 6
0
def unsetFavorite():
    result = request.get_json()
    requires = ["text"]
    if isValid(requires, result):
        textToFavorite = result["text"]
        L = [x[1:-1] for x in textToFavorite[1:-1].split(", ")]
        textToFavorite = " ".join(L).strip()

        # Can only favorite if you are logged in
        if not current_user.is_authenticated:
            return "Must be logged in"

        # Get the article ID
        article = Article.query.filter(
            Article.content == textToFavorite).first()
        if article is None:
            return "Article was not favorited"

        current_user.remove_favorite(article.id)
        db_session.commit()
        return "Removed from favorites"