|
|
@ -18,13 +18,8 @@ bp = Blueprint('post', __name__)
|
|
|
|
@bp.route('/<int:page>')
|
|
|
|
@bp.route('/<int:page>')
|
|
|
|
def posts(page):
|
|
|
|
def posts(page):
|
|
|
|
def tags_prepare(posts):
|
|
|
|
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()
|
|
|
|
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]
|
|
|
|
for tag,p_ids in tags:
|
|
|
|
|
|
|
|
tag.count = len(p_ids)
|
|
|
|
|
|
|
|
tag.post_ids = p_ids
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags = [t[0] for t in tags]
|
|
|
|
|
|
|
|
tags.sort(key=lambda x: (x.category.value, x.content) )
|
|
|
|
tags.sort(key=lambda x: (x.category.value, x.content) )
|
|
|
|
return tags
|
|
|
|
return tags
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +30,6 @@ def posts(page):
|
|
|
|
|
|
|
|
|
|
|
|
f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'))
|
|
|
|
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
|
|
|
|
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:
|
|
|
|
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
|
|
|
|
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
|
|
|
|
m_ratings = f_rating.matched if f_rating else RATING.safe.matched
|
|
|
|
|
|
|
|
|
|
|
|
# filter user's blacklist
|
|
|
|
# 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
|
|
|
|
blacklist_tags = [tb.content for tb in current_user.tag_blacklist] if current_user.is_authenticated else None
|
|
|
|
|
|
|
|
|
|
|
|
posts_query = Post.query
|
|
|
|
posts_query = Post.query
|
|
|
@ -72,9 +64,10 @@ def post_show(id):
|
|
|
|
# return redirect(url_for('.posts'))
|
|
|
|
# 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()
|
|
|
|
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:
|
|
|
|
# for tag,tag.count in tags_count:
|
|
|
|
# tag.endpoint = query_replace(dict(**session_rating(), tags=tag.content), url_for('.posts'))
|
|
|
|
# # tag.endpoint = query_replace(dict(**session_rating(), tags=tag.content), url_for('.posts'))
|
|
|
|
pass
|
|
|
|
# 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()
|
|
|
|
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(
|
|
|
|
return render_template(
|
|
|
|
'post/post.html',
|
|
|
|
'post/post.html',
|
|
|
|
post=post,
|
|
|
|
post=post,
|
|
|
|
tags=post.tags,
|
|
|
|
tags=tags,
|
|
|
|
comments=comments,
|
|
|
|
comments=comments,
|
|
|
|
editform=PostForm(
|
|
|
|
editform=PostForm(
|
|
|
|
id=post.id,
|
|
|
|
id=post.id,
|
|
|
|
referer=post_show.__name__,
|
|
|
|
referer=post_show.__name__,
|
|
|
|
source=post.source,
|
|
|
|
source=post.source,
|
|
|
|
parent=post.parent_id,
|
|
|
|
parent=post.parent_id,
|
|
|
|
tags=' '.join(t.content for t in post.tags),
|
|
|
|
tags=' '.join(t.content for t in tags),
|
|
|
|
rating=post.rating,
|
|
|
|
rating=post.rating,
|
|
|
|
status=post.status
|
|
|
|
status=post.status
|
|
|
|
),
|
|
|
|
),
|
|
|
|