|
|
|
@ -18,13 +18,8 @@ bp = Blueprint('post', __name__)
|
|
|
|
|
@bp.route('/<int:page>')
|
|
|
|
|
def posts(page):
|
|
|
|
|
def tags_prepare(posts):
|
|
|
|
|
tags = db.session.query(Tag, func.array_agg(Post.id)).join(Tag.posts).filter(Post.id.in_([p.id for p in posts])).group_by(Tag.id).all()
|
|
|
|
|
|
|
|
|
|
for tag,p_ids in tags:
|
|
|
|
|
tag.count = len(p_ids)
|
|
|
|
|
tag.post_ids = p_ids
|
|
|
|
|
|
|
|
|
|
tags = [t[0] for t in tags]
|
|
|
|
|
tags = db.session.query(Tag, func.count(Post.id), func.array_agg(Post.id)).join(Tag.posts).filter(Post.id.in_([p.id for p in posts])).group_by(Tag.id).all()
|
|
|
|
|
tags = [tag for tag, tag.count, tag.post_ids in tags]
|
|
|
|
|
tags.sort(key=lambda x: (x.category.value, x.content) )
|
|
|
|
|
return tags
|
|
|
|
|
|
|
|
|
@ -35,7 +30,6 @@ def posts(page):
|
|
|
|
|
|
|
|
|
|
f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'))
|
|
|
|
|
session['enforced_rating'] = f_rating.name if f_rating else None
|
|
|
|
|
# flash(f_rating.name if f_rating else None)
|
|
|
|
|
|
|
|
|
|
if current_user.is_authenticated and current_user.rating is RATING.explicit and f_rating is RATING.explicit:
|
|
|
|
|
return redirect(url_for('.posts')) # Fookin hack to fix the state after user's switch to RATING.explicit
|
|
|
|
@ -45,8 +39,6 @@ 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])
|
|
|
|
|
blacklist_tags = [tb.content for tb in current_user.tag_blacklist] if current_user.is_authenticated else None
|
|
|
|
|
|
|
|
|
|
posts_query = Post.query
|
|
|
|
@ -72,9 +64,10 @@ def post_show(id):
|
|
|
|
|
# return redirect(url_for('.posts'))
|
|
|
|
|
|
|
|
|
|
tags_count = db.session.query(Tag, func.count(Post.id)).join(Tag.posts).filter(Post.id==id).join(aliased(Post), Tag.posts).group_by(Tag).all()
|
|
|
|
|
for tag,tag.count in tags_count:
|
|
|
|
|
# tag.endpoint = query_replace(dict(**session_rating(), tags=tag.content), url_for('.posts'))
|
|
|
|
|
pass
|
|
|
|
|
# for tag,tag.count in tags_count:
|
|
|
|
|
# # tag.endpoint = query_replace(dict(**session_rating(), tags=tag.content), url_for('.posts'))
|
|
|
|
|
# pass
|
|
|
|
|
tags = [tag for tag,tag.count in tags_count]
|
|
|
|
|
|
|
|
|
|
comments = db.session.query(Comment).filter_by(post=post).filter_by(visible=True).order_by(Comment.id).all()
|
|
|
|
|
|
|
|
|
@ -84,14 +77,14 @@ def post_show(id):
|
|
|
|
|
return render_template(
|
|
|
|
|
'post/post.html',
|
|
|
|
|
post=post,
|
|
|
|
|
tags=post.tags,
|
|
|
|
|
tags=tags,
|
|
|
|
|
comments=comments,
|
|
|
|
|
editform=PostForm(
|
|
|
|
|
id=post.id,
|
|
|
|
|
referer=post_show.__name__,
|
|
|
|
|
source=post.source,
|
|
|
|
|
parent=post.parent_id,
|
|
|
|
|
tags=' '.join(t.content for t in post.tags),
|
|
|
|
|
tags=' '.join(t.content for t in tags),
|
|
|
|
|
rating=post.rating,
|
|
|
|
|
status=post.status
|
|
|
|
|
),
|
|
|
|
|