Example #1
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():  #if follow is clicked...
        user = User.query.filter_by(username=username).first(
        )  #check for a matching username in User db
        if user is None:  #if no matching username found in User db...
            flash(_('User %(username)s not found',
                    username=username.title()))  #flash message
            return redirect(
                url_for('main.index'))  #and redirect user to home page
        if user == current_user:  #if user attempts to follow themself...
            flash(_('Nice try, you cannot follow yourself.'))  #flash message
            return redirect(url_for(
                'main.user',
                username=username))  #and send them back to their profile
        current_user.follow(
            user
        )  #if user is NOT == None and NOT == current_user, follow the user that current_user wishes to follow
        db.session.commit()  #update the data in the database
        flash(
            _('You are now following %(username)s!',
              username=username.title()))  #flash confirmation message
        return redirect(url_for(
            'main.user',
            username=username))  #finally send them back to their profile page
    else:
        return redirect(
            url_for('main.index'
                    ))  #if form is not validated, redirect user to home page
Example #2
0
def unfollow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first(
        )  #sets user to the first match found or None if no match found
        if user is None:  #if no username match found...
            flash(_('User %(username)s not found',
                    username=username))  #flash message
            return redirect(url_for('main.index'))  #and then send user to home
        if user == current_user:  #if user tries to unfollow themselves...
            flash(
                _('Nice try %(username)s, you cannot unfollow yourself.',
                  username=username.title()))  #print flash message
            return redirect(url_for(
                'main.user',
                username=username))  #and then takes the user their page
        current_user.unfollow(
            user
        )  #if username is found and it is not the current_user's, process the unfollow
        db.session.commit()  #save changes in database
        flash(_('You no longer follow %(username)s',
                username=username.title()))  #flash message
        return redirect(url_for(
            'main.user', username=username))  #redirect user to their profile
    else:
        return redirect(
            url_for('main.index')
        )  #if submission cant be validated redirect user to home page
Example #3
0
def unlike_post(post_id):
    form = EmptyForm()
    if form.validate_on_submit():
        post = Post.query.filter_by(id=post_id).first()
        if post is None:
            flash('Post {} not found.'.format(post))
            return redirect(url_for('main.index'))
        current_user.unlike_post(post)
        db.session.commit()
        flash('Post removed from liked posts')
    return redirect(url_for('main.post_info', post_id=post_id))
Example #4
0
def unfollow_program(program_id):
    form = EmptyForm()
    if form.validate_on_submit():
        program = Program.query.filter_by(id=program_id).first()
        if program is None:
            flash(_('Program not found.'))
            return redirect(url_for('main.programs'))
        current_user.unfollow_program(program)
        db.session.commit()
        flash(_('You are not following %(name)s.', name=program.name))
    return redirect(request.referrer)
Example #5
0
def unfollow(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("main.index"))
        if user == current_user:
            flash("You cannot unfollow yourself")
            return redirect(url_for("main.user", username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash("You are not following {}".format(username))
        return redirect(url_for("main.user", username=username))
    return redirect(url_for("main.index"))
Example #6
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('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))
    return redirect(url_for('main.index'))
Example #7
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        _user = User.query.filter_by(username=username).first()
        if _user is None:
            flash('{} has not been invited to the party'.format(username))
            return redirect(url_for('main.index'))
        if _user == current_user:
            flash("nice try, but you can't follow yourself")
            return redirect(url_for('main.user', username=username))
        current_user.follow(_user)
        db.session.commit()
        flash("you're now following {}!".format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.user', username=username))
Example #8
0
def unfollow(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.unfollow(user)
        db.session.commit()
        flash(_('Вы успешно отписались от пользователя %(username)s', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #9
0
def unfollow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(name=username).first()
        if user is None:
            flash('User {} not found.'.format(username))
            return redirect(url_for('main.home'))
        if user == current_user:
            flash('You cannot unfollow yourself.')
            return redirect(url_for('main.user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash('You have unfollowed {}.'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.home'))
Example #10
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 %s not found' % username)
            return redirect(url_for('main.index'))
        if user == current_user.username:
            flash('YOu cannot follow yourself')
            return redirect(url_for('main.index'))
        current_user.follow(user)
        db.session.commit()
        flash('Your are follwing %s' % username)
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
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.profile', username = username))
        if user == current_user:
            flash(_('You cannot follow yourself'))
            return redirect(url_for('main.profile', username = username))
        current_user.follow(user)
        db.session.commit()
        flash(_('You are now following %(username)s', username = username))
        return redirect(url_for('main.profile', username = username))
    else:
        return redirect(url_for('main.home'))
Example #12
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} does not exist")
            return redirect(url_for("main.index"))
        if user == current_user:
            flash(f"Cannot follow yourself")
            return redirect(url_for("main.index"))
        current_user.follow(user)
        db.session.commit()
        flash(f"You are following {username}")
        return redirect(url_for("main.user", username=username))
    else:
        return redirect(url_for("main.index"))
Example #13
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'))
Example #14
0
def unfollow(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(request.referrer)
        if user == current_user:
            flash('You cannot unfollow yourself!')
            return redirect(request.referrer)
        current_user.unfollow(user)
        db.session.commit()
        flash('You are not following {}.'.format(username))
        return redirect(request.referrer)
    else:
        return redirect(request.referrer)
Example #15
0
def unfollow(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'))
        if user == current_user:
            flash('You can\'t unfollow yourself')
            return redirect(url_for('main.user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash(_('You are not following %(username)s', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #16
0
def follow(username):  # followbutton is rendered in User page
    form = EmptyForm()
    if form.validate_on_submit():  # run below once they press submit button
        user = User.query.filter_by(username=username).first()
        if user is None:  # if there is no user redirect to index
            flash('User {} not found.'.format(username))
            return redirect(url_for('main.index'))
        if user == current_user:  # if user tries to follow him/herself
            flash('You cannot follow yourself!')
            return redirect(url_for('main.user', username))
        current_user.follow(user)
        db.session.commit()
        flash('You are now following {}!'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #17
0
def delete_image():
    form = EmptyForm()
    if form.validate_on_submit():
        if current_user.avatar_img is None:
            flash(_('You do not have a custom avatar image'))
            return redirect(
                url_for('main.user', username=current_user.username))
        os.remove(
            os.path.join(current_app.config['UPLOAD_FOLDER'], 'avatars',
                         current_user.avatar_img))
        current_user.avatar_img = None
        db.session.commit()
        flash(_('Your picture has been deleted'))
        return redirect(url_for('main.user', username=current_user.username))
    else:
        return redirect(url_for('main.index'))
Example #18
0
def unfollow(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'))
        if user == current_user:
            flash('You cannot unfollow yourself!')
            return redirect(url_for('main.user',username=username))
        current_user.unfollow(user) 
        db.session.commit()
        flash(f'You are not followinng {username}')
        return redirect(url_for('main.user',username=username))
    else:   # validate_on_submit() 호출이 실패 할 수 있는 유일한 이유는 CSRF 토큰이 없거나 유효하지 않은 경우
        return redirect(url_for('main.index')) # 이 경우 애플리케이션을 홈페이지로 다시 리디렉션함
Example #19
0
def follow(username): # <username> 과 변수명 일치 
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
                                  #(db에있는 column= 변수명)
        if user is None:
            flash(f'User {username} not found')
            return redirect(url_for('main.index'))
        if user == current_user: # 현재 유저 본인이라면
            flash('You cannot follow yourself!')
        current_user.follow(user) 
        db.session.commit()
        flash(f'You are followung {username}!')
        return redirect(url_for('main.user', username=username)) 
    else:
        return redirect(url_for('main.index'))
Example #20
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 cannot follow yourself!'))
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash(_('You are following %(username)s!', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #21
0
def unfollow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        _user = User.query.filter_by(username=username).first()
        if _user is None:
            flash('{} has not been invited to the party'.format(username))
            return redirect(url_for('main.index'))
        if _user == current_user:
            flash("thou cannot unfollow oneself")
            return redirect(url_for('main.user', username=username))
        current_user.unfollow(_user)
        db.session.commit()
        flash('unfollowed {}'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.user', username=username))
Example #22
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.', 'warning')
            return redirect(url_for('main.index'))
        if user == current_user:
            flash('You cannot follow yourself!','warning')
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash('Congo you are growing socially','success')
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #23
0
def unfollow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if not user:
            flash(_('Usuário %(username)s não encontrado!', username=username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash(_('Função não permitida para seu próprio perfil!'))
            return redirect(url_for('main.user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash(_('Você deixou de seguir %(username)s.', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #24
0
def follow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if not user:
            flash(_('Usuário %(username)s não encontrado.', username=username))
            return redirect(url_for('main.index'))
        if user == current_user:
            flash(_('Ops, você não pode se seguir!'))
            return redirect(url_for('main.user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash(_('Você está seguindo %(username)s!', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #25
0
def unfollow(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 unfollow yourself!"))
            return redirect(url_for('main.user', username=username))
        current_user.unfollow(user)
        db.session.commit()  # pylint: disable=no-member
        flash(_('You are no longer following %(username)s.', username=username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #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("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 %(username)s!", username=username))
        return redirect(url_for("main.user", username=username))
    else:
        return redirect(url_for("main.index"))
Example #27
0
def unfollow(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.unfollow(user)
        db.session.commit()
        flash('取关{}成功'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #28
0
def unfollow(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('main.index'))
        if user == current_user:
            flash('You cannot unfollow yourself')
            redirect(url_for('main.user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash('You are no longer following {}.'.format(username))
        return redirect(url_for(
            'main.user', username=username))  #idk if we should send them here
    else:
        return redirect(url_for('main.index'))
Example #29
0
def unfollow(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.unfollow(user)
        db.session.commit()
        flash('取消关注: {}'.format(username))
        return redirect(url_for('main.user', username=username))
    else:
        return redirect(url_for('main.index'))
Example #30
0
def unfollow(username):
    form = EmptyForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if not user:
            flash(f"User {username} not found!")
            return redirect(url_for("main.index"))
        if user == current_user:
            flash(_("You cannot unfollow yourself!"))
            return redirect(url_for("main.user"), username=username)
        current_user.unfollow(user)
        db.session.commit()
        flash(_("You are no longer following %(username)s!",
                username=username))
        return redirect(url_for("main.user", username=username))
    else:
        return redirect(url_for("main.index"))