|
|
|
@ -42,12 +42,18 @@ def posts(page):
|
|
|
|
|
m_ratings = f_rating.matched if f_rating else RATING.safe.matched
|
|
|
|
|
|
|
|
|
|
# filter user's blacklist
|
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
|
f_tags = list(t for t in f_tags if t not in [tb.content for tb in current_user.tag_blacklist])
|
|
|
|
|
# if current_user.is_authenticated:
|
|
|
|
|
# f_tags = list(t for t in f_tags if t not in [tb.content for tb in current_user.tag_blacklist])
|
|
|
|
|
blacklist_tags = [tb.content for tb in current_user.tag_blacklist] if current_user.is_authenticated else None
|
|
|
|
|
|
|
|
|
|
posts_query = Post.query
|
|
|
|
|
if f_tags:
|
|
|
|
|
posts_query = posts_query.join(Post.tags).group_by(Post.id).filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags))
|
|
|
|
|
if f_tags or blacklist_tags:
|
|
|
|
|
posts_query = posts_query.join(Post.tags).group_by(Post.id)
|
|
|
|
|
if blacklist_tags:
|
|
|
|
|
subquery = db.session.query(Post.id).join(Tag.posts).filter(Tag.content.in_(blacklist_tags)).subquery()
|
|
|
|
|
posts_query = posts_query.filter(~Post.id.in_(subquery))
|
|
|
|
|
if f_tags:
|
|
|
|
|
posts_query = posts_query.filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags))
|
|
|
|
|
posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created.desc())
|
|
|
|
|
|
|
|
|
|
posts = posts_query.paginate(page, current_app.config.get('POSTS_PER_PAGE'))
|
|
|
|
@ -79,7 +85,7 @@ def post_show(id):
|
|
|
|
|
id=post.id,
|
|
|
|
|
referer=post_show.__name__,
|
|
|
|
|
source=post.source,
|
|
|
|
|
tags=" ".join([t.content for t in post.tags]),
|
|
|
|
|
tags=' '.join(t.content for t in post.tags),
|
|
|
|
|
rating=post.rating,
|
|
|
|
|
status=post.status
|
|
|
|
|
),
|
|
|
|
|