Пример #1
0
def follows_followed_follow(followed_id):
    user = User.get_user(followed_id)
    if user != None and not user.is_deleted():
        if not Follow.is_following_by_follower_and_followed(g.user.id, user.id):
            follow = Follow(g.user.id, user.id)
            db.session.add(follow)
            db.session.commit()
            emails.follower_notification(g.user, user)
        return redirect(url_for('user_thanks', username = user.username))
    abort(404)
Пример #2
0
 def test_follow_posts(self):
         # make four users
         u1 = User(nickname='john', email='*****@*****.**')
         u2 = User(nickname='susan', email='*****@*****.**')
         u3 = User(nickname='mary', email='*****@*****.**')
         u4 = User(nickname='david', email='*****@*****.**')
         db.session.add(u1)
         db.session.add(u2)
         db.session.add(u3)
         db.session.add(u4)
         # make four posts
         utcnow = datetime.utcnow()
         p1 = Post(body="post from john", author=u1,
                   timestamp=utcnow + timedelta(seconds=1))
         p2 = Post(body="post from susan", author=u2,
                   timestamp=utcnow + timedelta(seconds=2))
         p3 = Post(body="post from mary", author=u3,
                   timestamp=utcnow + timedelta(seconds=3))
         p4 = Post(body="post from david", author=u4,
                   timestamp=utcnow + timedelta(seconds=4))
         db.session.add(p1)
         db.session.add(p2)
         db.session.add(p3)
         db.session.add(p4)
         db.session.commit()
         # setup the followers
         u1.follow(u1)  # john follows himself
         print 'u1 is following u1'
         follower_notification(u1, u1)
         u1.follow(u2)  # john follows susan
         u1.follow(u4)  # john follows david
         u2.follow(u2)  # susan follows herself
         u2.follow(u3)  # susan follows mary
         u3.follow(u3)  # mary follows herself
         u3.follow(u4)  # mary follows david
         u4.follow(u4)  # david follows himself
         db.session.add(u1)
         db.session.add(u2)
         db.session.add(u3)
         db.session.add(u4)
         db.session.commit()
         # check the followed posts of each user
         f1 = u1.followed_posts().all()
         f2 = u2.followed_posts().all()
         f3 = u3.followed_posts().all()
         f4 = u4.followed_posts().all()
         assert len(f1) == 3
         assert len(f2) == 2
         assert len(f3) == 2
         assert len(f4) == 1
         assert f1 == [p4, p2, p1]
         assert f2 == [p3, p2]
         assert f3 == [p4, p3]
         assert f4 == [p4]
Пример #3
0
    def post(self, user_id):
        user = User.query.filter_by(id=user_id).first()
        emails.follower_notification(user, g.user)
        if not user:
            data = {"error": "Can't find user with id {}".format(user_id),
                    "is_follow": False}

        else:
            u = g.user.follow(user)
            emails.follower_notification(user, g.user)
            db.session.add(u)
            db.session.commit()
            data = {"success": "You are follow the user with id {}".format(user_id),
                    "is_follow": g.user.is_following(user)}
        return jsonify(**data)
Пример #4
0
def follow(nickname):
    user = User.query.filter_by(nickname=nickname).first()
    if user is None:
        flash('User ' + nickname + ' not found.')
        return redirect(url_for('index'))
    if user == g.user:
        flash('You can\'t follow yourself!')
        return redirect(url_for('user', nickname=nickname))
    u = g.user.follow(user)
    if u is None:
        flash('Cannot follow ' + nickname + '.')
        return redirect(url_for('user', nickname=nickname))
    db.session.add(u)
    db.session.commit()
    flash('You are now following ' + nickname + '!')
    follower_notification(user, g.user)
    return redirect(url_for('user', nickname=nickname))
Пример #5
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('User ' + username + ' not found.')
        return redirect(url_for('index'))
    if user == g.user:
        flash('You can\'t follow yourself!')
        return redirect(url_for('user', username=username))
    u = g.user.follow(user)
    if u is None:
        flash('Cannot follow ' + username + '.')
        return redirect(url_for('user', username=username))
    db.session.add(u)
    db.session.commit()
    flash('You are now following ' + username + '!')
    follower_notification(user, g.user)
    return redirect(url_for('user', username=username))
Пример #6
0
def follow(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('User %s not found.' % username)
        return redirect(url_for('index'))
    if user == current_user:
        flash('You can\'t follow yourself!')
        return redirect(url_for("user", username=username))
    u = current_user.follow(user)
    if u is None:
        flash('Cannot follow ' + username + '.')
        return redirect(url_for("user", username=username))
    db.session.add(u)
    db.session.commit()
    flash('You are now following ' + username + '!')
    follower_notification(user, current_user)
    return redirect(url_for("user", username=username))
Пример #7
0
def follow(nickname):
    user = User.query.filter_by(nickname=nickname).first()
    if user == None:
        flash('User ' + nickname + ' not found.')
        return redirect(url_for('index'))
    if user == g.user:
        flash(gettext('You can\'t follow yourself!'))
        return redirect(url_for('user', nickname=nickname))
    u = g.user.follow(user)
    if u is None:
        flash(gettext('Cannot follow %(nickname)s.', nickname = nickname))
        return redirect(url_for('user', nickname=nickname))
    db.session.add(u)
    db.session.commit()
    flash(gettext('You are now following %(nickname)s!', nickname = nickname))
    follower_notification(user, g.user)
    return redirect(url_for('user', nickname=nickname))
Пример #8
0
 def get(self, user_id):
     user = User.query.filter_by(id=user_id).first()
     if not user:
         flash('User ' + user.nickname + ' not found.')
         return redirect(url_for('IndexView:get_0'))
     # if user == g.user:
     #     flash('You can\'t follow yourself!')
     #     return redirect(url_for('UserView:profile', user_id=user.id))
     u = g.user.follow(user)
     if u is None:
         flash('Cannot follow ' + user.nickname + '.')
         return redirect(url_for('UserView:profile', user_id=user.id))
     emails.follower_notification(user, g.user)
     db.session.add(u)
     db.session.commit()
     name = user.nickname or user.full_name
     flash('You are now following ' + name + '!')
     return redirect(url_for('UserView:profile', user_id=user.id))
Пример #9
0
def follow(nickname):
    """ 关注 """
    user = User.query.filter_by(nickname=nickname).first()
    if user is None:
        flash(gettext('用户 %s 不存在!') % nickname)
        return redirect(url_for('leaf.index'))
    if user == g.user:
        flash(gettext('您不能关注自己!'))
        return redirect(url_for('main.user', nickname=nickname))
    # 关注用户
    u = g.user.follow(user)
    if u is None:
        flash(gettext('无法关注 %s !') % nickname)
        return redirect(url_for('main.user', nickname=nickname))
    db.session.add(u)
    db.session.commit()
    flash(gettext('您已关注 %s !') % nickname)
    # 通过邮件通知被关注
    follower_notification(user, g.user)
    return redirect(url_for('main.user', nickname=nickname))
Пример #10
0
def follow(nickname):
    user = User.query.filter_by(nickname=nickname).first()
    if user is None:
        flash("User %s not found." % nickname)

    if user == g.user:
        flash("You can't follow yourself")

    u = g.user.follow(user)

    if u is None:
        flash("Cannot follow %s." % nickname)
        return redirect(url_for("user", nickname=nickname))

    db.session.add(u)
    db.session.commit()

    flash("You are now following %s" % nickname)
    follower_notification(user, g.user)
    return redirect(url_for("user", nickname=nickname))