24 lines
966 B
Python
24 lines
966 B
Python
from flask import Blueprint, render_template
|
|
from flask_login import login_required, current_user
|
|
from sqlalchemy import desc
|
|
from ..models import Post, Visibility, ReviewStatus, Follow
|
|
|
|
bp = Blueprint("feed", __name__, url_prefix="/feed")
|
|
|
|
@bp.route("/")
|
|
def home():
|
|
return discover()
|
|
|
|
@bp.route("/discover")
|
|
def discover():
|
|
posts = Post.query.filter(Post.visibility == Visibility.public, Post.status == ReviewStatus.approved).order_by(desc(Post.published_at)).limit(100).all()
|
|
return render_template("feed/discover.html", posts=posts)
|
|
|
|
@bp.route("/following")
|
|
@login_required
|
|
def following():
|
|
ids = [f.followee_id for f in Follow.query.filter_by(follower_id=current_user.id).all()]
|
|
q = Post.query.filter(Post.user_id.in_(ids)).filter((Post.visibility == Visibility.followers) | (Post.visibility == Visibility.public))
|
|
posts = q.order_by(desc(Post.created_at)).limit(100).all()
|
|
return render_template("feed/following.html", posts=posts)
|