Python flask_login.current_user 模块,is_following() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用flask_login.current_user.is_following()

项目:zheye    作者:mathbugua    | 项目源码 | 文件源码
def follow(username):
    """????"""
    user = User.query.filter_by(username=username).first()
    if user is None:
        return jsonify(error=constant.INVALID_USER)
    if user == current_user:
        return jsonify(constant.CANNOT_CON_MYSELF)
    if current_user.is_following(user):
        return jsonify(error=constant.ALREADY_CON)
    try:
        current_user.follow(user)
    except Exception as e:
        return jsonify(constant.FAIL)

    current_user.notify_follower(user.id, "follow_user")
    return jsonify(error="")
项目:circleci-demo-python-flask    作者:CircleCI-Public    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('You are now following %s.' % username)
    return redirect(url_for('.user', username=username))
项目:circleci-demo-python-flask    作者:CircleCI-Public    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user.')
        return redirect(url_for('.user', username=username))
    current_user.unfollow(user)
    flash('You are not following %s anymore.' % username)
    return redirect(url_for('.user', username=username))
项目:Simpleblog    作者:Blackyukun    | 项目源码 | 文件源码
def follow(nickname):
    user = User.query.filter_by(nickname=nickname).first()
    if user is None:
        flash('??????')
        return redirect(url_for('user.index'))
    if current_user.is_following(user):
        flash('??????????')
        return redirect(url_for('user.users', nickname=nickname))
    current_user.follow(user)
    flash('???? %s?' % nickname)
    return redirect(url_for('user.users', nickname=nickname))

# ????
项目:Simpleblog    作者:Blackyukun    | 项目源码 | 文件源码
def unfollow(nickname):
    user = User.query.filter_by(nickname=nickname).first()
    if user is None:
        flash('??????')
        return redirect(url_for('user.index'))
    if not current_user.is_following(user):
        flash('?????????????')
        return redirect(url_for('user.users', nickname=nickname))
    current_user.unfollow(user)
    flash('?????? %s ?' % nickname)
    return redirect(url_for('user.users', nickname=nickname))
项目:smart-iiot    作者:quanpower    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    db.session.commit()
    flash('You are now following %s.' % username)
    return redirect(url_for('.user', username=username))
项目:smart-iiot    作者:quanpower    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user.')
        return redirect(url_for('.user', username=username))
    current_user.unfollow(user)
    db.session.commit()
    flash('You are not following %s anymore.' % username)
    return redirect(url_for('.user', username=username))
项目:copyflask_web    作者:superchilli    | 项目源码 | 文件源码
def follow(username):
    user= User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('You are now following %s.' % username)
    return redirect(url_for('.user', username=username))
项目:copyflask_web    作者:superchilli    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user.')
        return redirect(url_for('.user', username=username))
    current_user.unfollow(user)
    flash('You are not following %s anymore.' % username)
    return redirect(url_for('.user', username=username))
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def follow(username):
    user=User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('You are now following %s.' % username)
    return redirect(url_for('.user', username=username))
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user.')
        return redirect(url_for('.user', username=username))
    current_user.unfollow(user)
    flash('You are not following %s anymore.' % username)
    return redirect(url_for('.user', username=username))
项目:minitweet    作者:alifaki077    | 项目源码 | 文件源码
def follow_or_unfollow(username):
    """
    follow_or_unfollow user
    the request will sent with ajax
    example returned json:
        status: either "good" or "error"
        follow: if user follow the user follow = True else follow = None
        msg: if there is alert msg="some alert" else msg=None
        category: category of the msg (warning, primary, success)
    """
    msg = None
    category = None
    follow = False
    user = User.query.filter_by(name=username).first_or_404()
    if not current_user.is_authenticated:
        status = "error"
        msg = "Please Login or signup first"
        category = "warning"
    elif not current_user.confirmed:
        status = "error"
        msg = "Please confirm your email first"
        category = "warning"
    else:
        status = "good"
        if not current_user.is_following(user):
            follow = True
            current_user.follow(user)
        elif current_user.is_following(user):
            current_user.unfollow(user)
        db.session.add(current_user)
        db.session.commit()
    return jsonify({"status": status,
                    "msg": msg,
                    "category": category,
                    "follow": follow
                    })
项目:zheye    作者:mathbugua    | 项目源码 | 文件源码
def unfollow(username):
    """????"""
    user = User.query.filter_by(username=username).first()
    if user is None:
        return jsonify(error=constant.INVALID_USER)
    if not current_user.is_following(user):
        return jsonify(error=constant.NO_CON)
    try:
        current_user.unfollow(user)
    except Exception as e:
        return jsonify(constant.FAIL)

    return jsonify(error="")
项目:LivroFlask    作者:antoniocsz    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('You are now following {}'.format(username))
    return redirect(url_for('.user', username=username))
项目:LivroFlask    作者:antoniocsz    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not already following this user.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('You are not following {} anymore.'.format(username))
    return redirect(url_for('.user', username=username))
项目:blog    作者:hukaixuan    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user.')
        return redirect('.user', username=username)
    current_user.follow(user)
    flash('You are now following %s.' %username)
    return redirect(url_for('.user', username=username))
项目:blog    作者:hukaixuan    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user.')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user.')
        return redirect('.user', username=username)
    current_user.unfollow(user)
    flash('You are not following %s anymore.' %username)
    return redirect(url_for('.user', username=username))
项目:Faiwong-s-blog    作者:Fai-Wong    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash(u'????')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash(u'?????????')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash(u'???? %s.' % username)
    return redirect(url_for('.user', username=username))
项目:Faiwong-s-blog    作者:Fai-Wong    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash(u'????')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash(u'????????')
        return redirect(url_for('.user', username=username))
    current_user.unfollow(user)
    flash(u'?????? %s' % username)
    return redirect(url_for('.user', username=username))
项目:MyFlasky    作者:aliasxu    | 项目源码 | 文件源码
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('You are already following this user')
        return  redirect(url_for('.user',username=username))
    current_user.follow(user)
    flash('You are now following %s' %username )
    return redirect(url_for('.user',username=username))


#??????
项目:MyFlasky    作者:aliasxu    | 项目源码 | 文件源码
def unfollow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user')
        return redirect(url_for('.index'))
    if not current_user.is_following(user):
        flash('You are not following this user')
        return redirect(url_for('.user',username=username))
    current_user.unfollow(user)
    flash('You are not following %s anymore' %username)
    return redirect(url_for('.user',username=username))

#?????