Exemplo n.º 1
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.following(user)
    flash('You are now following %s.' % username)
    return redirect(url_for('.user', username=username))
Exemplo n.º 2
0
def follow(username):
    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):
        flash('关注失败,不可重复关注。')
        return redirect(url_for('main.user',username=username))
    current_user.following(user)
    flash('关注成功。')
    return redirect(url_for('main.user',username=username))
Exemplo n.º 3
0
def index():

    if(current_user.is_authenticated):
        feed_images = Images.select().where(Images.user.in_(current_user.following())).order_by(Images.created_at.desc())
        myidols = User.select().join(Follows, on=(Follows.myidol_id == User.id)).where(Follows.myfan_id == current_user.id)
        return render_template('home.html', feed_images = feed_images, user=myidols)
    else:
        return render_template('signin.html')
def index():
    if current_user.is_authenticated:
        allposts = Post.select().join(User).where(
            (Post.user_id.not_in(current_user.following()))
            & ~(Post.user.is_private)
            & (Post.user != current_user.id)).order_by(Post.created_at.desc())
        return render_template('users/explore.html', allposts=allposts)
    allposts = Post.select().join(User).where(~User.is_private).order_by(
        Post.created_at.desc())
    return render_template('users/explore.html', allposts=allposts)
Exemplo n.º 5
0
def index():
    if current_user.is_authenticated:
        allposts = Post.select().join(User).where(
            (Post.user_id.in_(current_user.following()) |
             (Post.user_id == current_user.id))).order_by(
                 Post.created_at.desc())
        return render_template('home.html', allposts=allposts)
    allposts = Post.select().join(User).where(~User.is_private).order_by(
        Post.created_at.desc())
    # return render_template('home.html', allposts=allposts)
    return redirect(url_for('users.index'))
Exemplo n.º 6
0
def display_update():
    form = UpdateDetailsForm()
    form.username.data = current_user.username
    form.email.data = current_user.email
    post_count = Post.select().where(Post.user == current_user)
    followers_count = current_user.followers()
    following_count = current_user.following()
    return render_template('update.html',
                           form=form,
                           username=current_user.username,
                           email=current_user.email,
                           post_count=post_count,
                           followers_count=followers_count,
                           following_count=following_count)
Exemplo n.º 7
0
def index():
    """
	Need to retrieve the posts where current user is "ALLOWED" to follow
	1. Select posts whom current user is following
		a. if followee.is_public == False
		b. Need to ensure Relationship is approved by followee
	2. Select posts from self
	"""
    posts = None
    if current_user.is_authenticated:
        try:
            posts = Post.select().where(
                (Post.user_id == current_user.following())
                | (Post.user_id == current_user.id)).order_by(
                    Post.updated_at.desc())
        except:
            flash("There are no posts to be displayed, start following people",
                  "info")
        finally:
            return render_template('index.html', posts=posts)
    else:
        return render_template('index.html', posts=posts)
Exemplo n.º 8
0
def follow(id):
    user = User.query.get_or_404(id)
    if current_user.can(Permission.FOLLOW) and current_user.following(user):
        flash('关注成功!')
    return redirect(url_for('user.user_center', id=user.id))
Exemplo n.º 9
0
def my_album():
    my_albums = models.Images.select().where(
        models.Images.user.in_(current_user.following()))
    #message_stream = models.Message.select().where(models.Message.user << models.User.following())
    return render_template('my_album.html', my_albums=my_albums)
Exemplo n.º 10
0
def our_images():
    images_stream = models.Images.select().where(
        models.Images.user.in_(current_user.following()))
    #message_stream = models.Message.select().where(models.Message.user << models.User.following())
    return render_template('show_image.html', images_stream=images_stream)
Exemplo n.º 11
0
def my_message():
    message_stream = models.Message.select().where(
        models.Message.user.in_(current_user.following()))
    #message_stream = models.Message.select().where(models.Message.user << models.User.following())
    return render_template('result_uploads.html',
                           message_stream=message_stream)