Exemple #1
0
def follow(id):
    '关注用户'
    user = User.query.get_or_404(id)
    if user != current_user and not current_user.is_following(user):
        current_user.follow(user)
    fans_num = user.fans.count() - 1
    return jsonify({"fans_num": fans_num})
Exemple #2
0
def follow_user(username):
	user = User.query.filter_by(username=username).first()
	if user is not None:
		current_user.follow(user)
	else:
		abort(404)
	return redirect(url_for('main.user_profile', username=username))
Exemple #3
0
def follow(userid):
    user = User.query.get_or_404(userid)
    if current_user.is_following(user):
        flash(u'您已关注过%s, 无需再次关注' % user.username)
        return redirect(url_for('main.user', userid=user.id))
    current_user.follow(user)
    flash(u'您现在已关注%s' % user.username)
    return redirect(url_for('main.user', userid=user.id))
Exemple #4
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('the user is not valid')
        return redirect(request.referrer)
    if current_user.is_invalid():
        flash('你当前权限受限,不能进行关注操作')
        return redirect(request.referrer)
    current_user.follow(user)
    return redirect(url_for('main.user', username=user.username))
Exemple #5
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid User')
        return redirect(url_for('main.index'))
    if current_user.is_following(user):
        flash('You have already following this user')
        return redirect('auth.user', username=username)
    current_user.follow(user)
    return redirect(url_for('auth.user', username=username))
Exemple #6
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Usuario invalido.')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('Tu ya sigues a este usuario.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('Ahora sigues a %s.' % username)
    return redirect(url_for('.user', username=username))
Exemple #7
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('非法用户')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('该用户你已经关注了.')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('已成功关注该用户 %s.' % username)
    return redirect(url_for('.user', username=username))
Exemple #8
0
def follow(username):
    u = User.query.filter_by(username=username).first()
    if u is None:
        flash(u'未找到指定用户')
        return redirect(url_for('.index'))
    if current_user.is_following(u):
        flash(u'你已经关注他了')
        return redirect('.user', username=username)
    current_user.follow(u)
    flash(u'关注了{0}'.format(username))
    return redirect(url_for('.user', username=username))
Exemple #9
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('Invalid user')
        return redirect(url_for('main.index'))
    if current_user.is_following(user):
        flash('You have follow this user already.')
        return redirect(url_for('main.user', username=username))
    current_user.follow(user)
    flash('Follow user %s successfully' % username)
    return redirect(url_for('main.user', username=username))
Exemple #10
0
def follow(username):
    u = User.query.filter_by(username=username).first()
    if u is None:
        flash("Invalid user")
        return redirect(url_for(".index"))
    if current_user.is_following(u):
        flash("Already following")
        return redirect(url_for(".user", username=username))
    current_user.follow(u)
    flash("You are following %s." % username)
    return redirect(url_for(".user", username=username))
Exemple #11
0
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))
Exemple #12
0
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))
Exemple #13
0
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))
Exemple #14
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('没有这个用户。')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('你已经关注Ta了!')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('你关注了 %s.' % username)
    return redirect(url_for('.user',username=username))
Exemple #15
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('无效用户')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash('您此前已关注该用户')
        return redirect(url_for('.user', username=username))
    current_user.follow(user)
    flash('您关注了%s')
    return redirect(url_for('.user', username=username))
Exemple #16
0
def follow(id):
    user = User.query.filter_by(id=id).first()
    if user is None:
        flash(u'关注的用户不存在')
        return redirect(url_for('.index'))
    if current_user.is_following(user):
        flash(u'您已经关注过此用户了')
        return redirect(url_for('.index'))
    current_user.follow(user)
    flash(u'关注%s成功' %user.username)
    return redirect(url_for('.user', id=id))
Exemple #17
0
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))
Exemple #18
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('User {} not found.'.format(username))
        return redirect(url_for('index'))
    if user == current_user:
        flash('You cannot follow yourself!')
        return redirect(url_for('user', username=username))
    current_user.follow(user)
    db.session.commit()
    flash('You are following {}!'.format(username))
    return redirect(url_for('user', username=username))
def follow(username):
	user = User.query.filter_by(username=username).first()
	if user is None:
		flash('Пользователь {} не найден!'.format(username))
		return(url_for('index'))
	if user == current_user:
		flash('вы не можете следить за собой!')
		return redirect(url_for('user', username=username))
	current_user.follow(user)
	db.session.commit()
	flash('Теперь вы подписанны на {}!'.format(username))
	return redirect(url_for('user', username=username))
Exemple #20
0
def dofollow():
    try:
        id = int(request.form['id'])
    except KeyError:
        abort(400)
    followee = User.from_id(id)
    if followee is None:
        abort(404)
    current_user.follow(followee)
    followee.addnewnote(user_from=current_user.id,
                        type=Notification.TYPE_FOLLOW,
                        )
    return 'done!'
Exemple #21
0
def follow(user_id):
    user = User.query.get(user_id)
    if not user:
        abort(404)
    if request.method == "GET":
        if user_id == current_user.id:
             user.check_follower()
        return render_template("user/follow.html", user=user, followers=user.followers.all())
    else:
        if user.id == current_user.id:
            return jsonify(status=500, message="关注自己?!别自恋了好伐?")
        current_user.follow(user)
        new_url = url_for('user.unfollow', user_id = user.id)
        return jsonify(data=user.id, status=200, message="取消关注", newurl=new_url)
Exemple #22
0
def follow(username):
    """
    :summary: 关注用户视图函数
    :param username:
    :return:
    """
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('用户不存在')
        return redirect(url_for('main.index'))
    if current_user.is_following(user):
        return redirect(url_for('main.users', username=username))
    current_user.follow(user)
    flash('成功关注了用户%s' % username)
    return redirect(url_for('main.users', username=username))
def follow(username):
    """
    Follow route to enable current user to follow this specified user
    :param username: username of the intended followee
    :return: a redirect to home page
    """
    author = AuthorAccount.query.filter_by(username=username).first()

    # current user can not follow someone who is not there
    if author is None:
        flash(message="Author %s not found" % username, category="error")
        return redirect(url_for("home.home"))

    # current user can not follow themselves
    if author == current_user:
        flash(message="You can't follow yourself!", category="error")
        return redirect(url_for("dashboard", username=current_user.username))

    u = current_user.follow(author)

    if u is None:
        flash(message="Can't follow %s" % username, category="error")
        return redirect(url_for("home.home"))

    db.session.add(u)
    db.session.commit()
    flash(message="You are now following %s" % username, category="success")
    return redirect(url_for("home.home"))
Exemple #24
0
def follow(username):
    if not current_user.is_authenticated:
        return jsonify(message='Login required.'), 403
    if not current_user.confirmed:
        return jsonify(message='Confirm account required.'), 400
    if not current_user.can('FOLLOW'):
        return jsonify(message='No permission.'), 403

    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_following(user):
        return jsonify(message='Already followed.'), 400

    current_user.follow(user)
    if user.receive_collect_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return jsonify(message='User followed.')
Exemple #25
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash(f'User {username} not found')
            return redirect(url_for('main.index'))
        elif user == current_user:
            flash('You can not follow yourself')
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash(f'You are now following {username}')
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #26
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash(_('User %(username)s not found.', username=username))
            return redirect(url_for('index'))
        if user == current_user:
            flash(_('You cannot follow yourself!'))
            return redirect(url_for('user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash(_('You are following %(username)s!', username=username))
        return redirect(url_for('user', username=username))
    else:
        return redirect(url_for('index'))
Exemple #27
0
def follow(username):
    user = User.query.filter_by(username=username).first()

    if user is None:
        flash('User {} not found'.format(username))
        return redirect(url_for('index'))

    if user == current_user:
        flash('You cannot follow yourself!')
        return redirect(url_for('user', username=username))

    current_user.follow(user)
    db.session.commit()
    flash('You are following {}!'.format(username))

    return redirect(url_for('user', username=username))
Exemple #28
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash(_('User %(username)s not found.', username=username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash(_("You can't follow yourself!"))
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()  # pylint: disable=no-member
        flash(_('You are now following %(username)s!', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #29
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash(_('Пользователь %(username)s не найден.', username=username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash(_('Вы не можете подписаться на себя!'))
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash(_('Вы подписаны на %(username)s!', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #30
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash("User {} not found.".format(username))
            return redirect(url_for("index"))
        if user == current_user:
            flash("You cannot follow yourself!")
            return redirect(url_for("user", username=username))
        current_user.follow(user)
        db.session.commit()
        flash("You are following {}!".format(username))
        return redirect(url_for("user", username=username))
    else:
        return redirect(url_for("index"))
def profile(user_id):

    user_from_table = User.query.filter_by(uid=user_id).first()
    posts_by_user = user_from_table.posts.order_by(desc(Post.posted_at))

    if request.method == 'GET':
        print("user_from_table.uid ", user_from_table.uid)
        print("current_user.followed", current_user.followed)
        return render_template('profile.html',
                               user_from_table=user_from_table,
                               posts_by_user=posts_by_user,
                               current_user=current_user)

    if request.method == 'POST':
        new_friend_uid = request.form['javascript_data']
        current_user_uid = current_user.uid

        # newFriend = Followers(follower_id = current_user_uid, followed_id = new_friend_uid)
        # db.session.add(newFriend)
        # db.session.commit()
        if current_user.follow(user_from_table, db.session):
            flash(user_from_table.firstname + " added to your friend list.")
        else:
            flash("There was some problem adding " +
                  user_from_table.firstname + " .")
        return "Friend Added"
Exemple #32
0
def follow(username):
    """关注的路由与视图函数"""
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('无效的用户')
        return redirect(url_for('.index'))

    if current_user.is_following(user):
        flash('你已经关注了这个用户')
        # 关注了用户后调到自己的详情页
        return redirect(url_for('.user', username=username))

    # 关注用户
    current_user.follow(user)
    db.session.commit()
    flash('你现在关注了 %s.' % username)
    return redirect(url_for('.user', username=username))
Exemple #33
0
def follow(username):
    user = User.query.filter_by(username=username).first()

    if user is None:
        flash(f"User {username} was not found")
        return redirect(url_for('home'))

    if user == current_user:
        flash('You cannot follow yourself!')
        return redirect(url_for('profile', username=username))

    current_user.follow(user)
    db.session.commit()

    flash(f"You are now following {username}!")

    return redirect(url_for('profile', username=username))
Exemple #34
0
def follow(username):
    '''route to allow users to follow another users post'''
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:  #if there is no such user
            flash('User {} not found.'.format(username))
            return redirect(url_for('main.index'))
        if user == current_user:  #if the user is the current user
            flash('You cannot follow yourself!')
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)  #otherwise allow user to follow user
        db.session.commit()  #commit changes to database
        flash('You are following {}!'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #35
0
def follow_user():
    follow_form = FollowUserForm()
    if follow_form.validate_on_submit():
        friend_name = follow_form.username.data
        friend_code = follow_form.friend_code.data
        friend = User.query.filter(User.username == friend_name).first()
        if friend:
            if friend.friend_code == friend_code:
                current_user.follow(friend)
                flash('You are now following {}'.format(friend.username))
            else:
                flash('I am sorry.  It seems the friend code you entered is invalid.')
                return redirect(url_for('todo.follow_user'))
            return redirect(url_for('todo.home'))
        else:
            flash('I am sorry.  It seems that user is not in our database.  Please check the spelling of their name.')
    return render_template('todo/follow_user.html', follow_form=follow_form)
Exemple #36
0
def follow(username):
    """
    关注
    """
    user = User.query.filter_by(username=username).first()
    if user is None:
        # flash('User {} not found'.format(username))
        flash(_("User %(username)s not found", username=username))  # 为了翻译,只能放弃format
        return redirect(url_parse(index))
    if user == current_user:
        flash(_('You cannot follow yourself!'))
        return redirect(url_for('main.user', username=username))  # 回到用户主页
    current_user.follow(user)
    db.session.commit()
    # flash('已关注 {}'.format(username))
    flash(_('You are following %(username)s!', username=username))
    return redirect(url_for('main.user', username=username))
Exemple #37
0
def follow(username):
    users = User.query.order_by(User.username.desc()).all()
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('User {} not found.'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            # flash('You cannot follow yourself!')
            return redirect(url_for('user', username=username))
        current_user.follow(user)
        db.session.commit()
        # flash('You are following {}!'.format(username))
        return redirect(url_for('user', username=username))
    else:
        return redirect(url_for('index'), users=users)
Exemple #38
0
def follow(username):
    '''
        define follow operations
    :param username: username
    :return:
    '''

    user = User.query.filter_by(username=username).first()
    if user is None or user.username == current_user.username:
        flash(u'无效用户名')
        return redirect(url_for('index.index_page'))
    if current_user.is_following(user):
        flash(u'你已经关注了这个用户!')
        return redirect(url_for('auth.user_detail', username=username))
    current_user.follow(user)
    flash(u'您从现在起关注了 %s.' % username)
    return redirect(url_for('auth.user_detail', username=username))
Exemple #39
0
def follow(username):
    if not current_user.is_authenticated:
        return jsonify(message='Требуется войти в свою учетную запись'), 403
    if not current_user.confirmed:
        return jsonify(
            message='Требуется подтверждение регистрации аккаунта'), 400
    if not current_user.can('FOLLOW'):
        return jsonify(message='Доступ запрещен'), 403

    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_following(user):
        return jsonify(message='Уже подписан. Already followed.'), 400

    current_user.follow(user)
    if user.receive_collect_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return jsonify(message='Вы подписались на этого пользователя')
Exemple #40
0
def follow(username):
    """
    Dockydocstring
    """
    #pylint: disable=redefined-outer-name
    
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('User {} not found.'.format(username))
        return redirect(url_for('main.index'))
    if user == current_user:
        flash('You cannot follow yourself!')
        return redirect(url_for('main.user', username=username))
    current_user.follow(user)
    db.session.commit()
    flash('You are following {}!'.format(username))
    return redirect(url_for('main.user', username=username))
def follow(idol_id):
    idol = User.get_by_id(idol_id)

    if current_user.follow(idol):
        # flash message
        return redirect(url_for('users.show', username=idol.username))
    else:
        return redirect(url_for('users.show', username=current_user.username))
Exemple #42
0
def follow(username):
    """
    Dodaje danego użytkownika do obserwowanych dla aktualnie zalogowanego użytkownika
    :param username: user
    :return: przekierowanie do user lub index
    """
    user_follow = User.query.filter_by(username=username).first()
    if user_follow is None:
        flash(_('User %(username)s not found.', username=username))
        return redirect(url_for('main.index'))
    if user_follow == current_user:
        flash(_('You cannot follow yourself!'))
        return redirect(url_for('main.user', username=username))
    current_user.follow(user_follow)
    db.session.commit()
    flash(_('You are following %(username)s!', username=username))
    return redirect(url_for('main.user', username=username))
Exemple #43
0
def follow(username):
    print('------------------------------有请求来')
    if not current_user.is_authenticated:
        return jsonify(message='需要登陆'), 403
    if not current_user.confirmed:
        return jsonify(message='需要验证账号'), 400
    if not current_user.can('FOLLOW'):
        return jsonify(message='没有权限'), 403

    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_following(user):
        return jsonify(message='已经关注'), 400

    current_user.follow(user)
    if current_user.receive_follow_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return jsonify(message='已关注')
Exemple #44
0
def create(idol_id):
    idol = User.get_by_id(idol_id)
    if current_user.follow(idol):
        flash(f"You send follow request to {idol.username}","success")
        return redirect(url_for('users.show',username=idol.username))
    else:
        flash(f"You not yet follow {idol.username}","danger")
        return render_template('users/show.html',username=idol.username)
Exemple #45
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash(_l('User %(username)s not found.', username=username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash(_l('You cannot follow yourself.'))
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)  # 关注该用户
        db.session.commit()
        flash(_l('Successfully followed %(username)s.',
                 username=user.username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #46
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    # 关注的用户不存在 则重定向到首页
    if user is None:
        flash('User {} not found.'.format(username))
        return redirect(url_for('index'))

    # 不能关注自身
    if user == current_user:
        flash('不能关注自己!')
        return redirect(url_for('user', username=username))

    current_user.follow(user)
    db.session.commit()
    flash('关注 {} 成功!'.format(username))
    # 关注某人成功后进入该用户首页
    return redirect(url_for('user', username=username))
Exemple #47
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('User {} not found'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            flash('You cannot follow yourself!!')
            return redirect(url_for('user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash('You are now following {}!'.format(username))
        return redirect(url_for('user', username=username))
    # The only way this failse is if there isnt a CSRF token
    else:
        return redirect(url_for('index'))
Exemple #48
0
def follow(username):
    """关注"""
    if not current_user.is_authenticated:
        return jsonify(message='请先登录.'), 403  # jsonify生成json相应格式,并返回提示消息
    if not current_user.confirmed:
        return jsonify(message='请先验证邮箱.'), 400
    if not current_user.can('FOLLOW'):
        return jsonify(message='没有权限.'), 403

    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_followed(user):
        return jsonify(message='已经关注过.'), 400

    current_user.follow(user)
    if user.receive_collect_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return jsonify(message='关注成功.')
Exemple #49
0
def follow(username):
    """关注"""
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('用户:{} 不存在'.format(username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash('不能关注自己')
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash('您已经成功关注: {}'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Exemple #50
0
def follow(id, full_name):
    user = db.session.query(User).filter(User.id == id,
                                         User.full_name == full_name).first()
    if user is None:
        flash('User {} not found.'.format(full_name))
        return redirect(url_for('main.index'))
    if user == current_user:
        flash('You cannot follow yourself!')
        return redirect(url_for('main.user', id=id, full_name=full_name))
    current_user.follow(user)
    db.session.commit()
    n = user.add_notification('new_follower',
                              {"count": current_user.new_followers() + 1},
                              related_id=current_user.id,
                              permanent=True)
    flash('You are following {}!'.format(full_name))
    return redirect(url_for('main.user', id=id, full_name=full_name))
Exemple #51
0
def follow(username):
    user = User.query.filter_by(username=username).first()

    if user is None:
        flash("User does not exist!", "danger")
        return redirect(url_for("dashboard"))

    if current_user.is_following(user):
        flash("You are already following this user!", "info")
        return redirect(url_for("userProfile", username=username))

    current_user.follow(user)
    db.session.commit()

    flash("You are now following {}".format(username), "success")

    return redirect(url_for("userProfile", username=username))
Exemple #52
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        # 未找到对应的用户
        # flash('User {} not found.'.format(username))
        flash(_('User %(username)s not found.', username=username))
        return redirect(url_for('main.index'))
    if user == current_user:
        # 如果用户是当前用户
        flash(_('You cannot follow yourself!'))
        print("关注成功跳转:", url_for('main.user', username=username))
        return redirect(url_for('main.user', username=username))
    current_user.follow(user)
    db.session.commit()
    # flash('You are following {}!'.format(username))
    flash(_('You are following %(username)s!', username=username))
    return redirect(url_for('main.user', username=username))
Exemple #53
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first_or_404()
        if not user:
            flash(f'User {username} is not found', 'info')
            return redirect(url_for('index'))
        elif user == current_user:
            flash('You cannot follow yourself', 'info')
            return redirect(url_for('user', username=username))
        else:
            current_user.follow(user)
            db.session.commit()
            flash(f'You are following {username}!', 'success')
            return redirect(url_for('user', username=username))
    else:
        return redirect(url_for('index'))
Exemple #54
0
def follow(username):
    error = None
    profile_user = User.query.filter_by(name=username).first()
    if profile_user is not None:
        if not current_user.id == profile_user.id:
            if not current_user.is_following(profile_user):
                new_follow = current_user.follow(profile_user)
                db.session.add(new_follow)
                db.session.commit()
            else:
                flash("You are already following this user.")
    return redirect(url_for('users.user_profile', username=username))
Exemple #55
0
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
                    })
Exemple #56
0
def person(pyname):
    print('view-args', request.view_args)
    print('endpoint', request.endpoint)
    login_form = LoginForm()
    register_form = RegistrationForm()
    user = User.query.filter_by(pyname=pyname).first()
    if user is None:
        # test
        return redirect(url_for('blog.articles'))

    if request.method == 'POST':
        data = request.get_json(force=True)
        uid = data['uid']
        user1 = User.query.get(int(uid))
        current_user.unfollow(user1) if current_user.is_following(user1) else current_user.follow(user1)
        follows_count = {'followers_count': user.followers.count(), 'followees_count': user.followees.count()}
        return json.dumps(follows_count)

    is_following = current_user.is_following(user)

    return render_template('profile/people.html', user=user, is_following=is_following,
                           login_form=login_form, register_form=register_form)
Exemple #57
0
def follow(user_id):
    user = User.query.get(user_id)
    current_user.follow(user)
    db.session.commit()
    return make_json_response("", 204)
Exemple #58
0
def follow(id):
    user = User.query.get_or_404(id)
    if not current_user.is_following(user):
        current_user.follow(user)
        return jsonify({'result':True})
    return jsonify({'result':False})
Exemple #59
0
def subscribe(id):
    po_line = PO_line.query.get_or_404(id)
    current_user.follow(po_line)
    return 'subscribed'
Exemple #60
0
def follow(username: str):
    user = User.query.filter_by(username=username).first_or_404()
    if not current_user.is_following(user):
        current_user.follow(user)
    return redirect(url_for('main.profile', username=username))