|
|
|
@ -10,7 +10,7 @@ from sqlalchemy.orm import aliased
|
|
|
|
|
from yadc import db
|
|
|
|
|
from yadc.forms import UploadForm, CommentForm, PostForm
|
|
|
|
|
from yadc.models import FILETYPE, RATING, POST_STATUS, Post, Tag, Comment, moderator_required
|
|
|
|
|
from yadc.utils import query_replace, flasherrors
|
|
|
|
|
from yadc.utils import query_replace, flasherrors, session_rating
|
|
|
|
|
|
|
|
|
|
bp = Blueprint('post', __name__)
|
|
|
|
|
|
|
|
|
@ -23,17 +23,23 @@ def posts(page):
|
|
|
|
|
for tag,p_ids in tags:
|
|
|
|
|
tag.count = len(p_ids)
|
|
|
|
|
tag.post_ids = p_ids
|
|
|
|
|
tag.endpoint = query_replace({'tags': tag.content}, url_for('.posts'))
|
|
|
|
|
|
|
|
|
|
tags = [t[0] for t in tags]
|
|
|
|
|
tags.sort(key=lambda x: (x.category.value, x.content) )
|
|
|
|
|
return tags
|
|
|
|
|
|
|
|
|
|
# PARSING ARGUMENTS
|
|
|
|
|
if request.args.get('tags') == '':
|
|
|
|
|
return redirect(query_replace({}, url_for('.posts')))
|
|
|
|
|
f_tags = request.args.get('tags', '').split()
|
|
|
|
|
# f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'), RATING.safe)
|
|
|
|
|
f_rating = current_user.rating if current_user.is_authenticated else RATING.safe
|
|
|
|
|
m_ratings = f_rating.matched
|
|
|
|
|
|
|
|
|
|
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 f_rating is None:
|
|
|
|
|
f_rating = current_user.rating
|
|
|
|
|
m_ratings = f_rating.matched if f_rating else RATING.safe.matched
|
|
|
|
|
|
|
|
|
|
# filter user's blacklist
|
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
@ -47,9 +53,6 @@ def posts(page):
|
|
|
|
|
posts = posts_query.paginate(page, current_app.config.get('POSTS_PER_PAGE'))
|
|
|
|
|
tags = tags_prepare(posts.items)
|
|
|
|
|
|
|
|
|
|
# BRUH
|
|
|
|
|
session['index_settings'] = dict(tags=request.args.get('tags', ''), rating=f_rating.name)
|
|
|
|
|
|
|
|
|
|
return render_template('post/index.html', posts=posts, tags=tags)
|
|
|
|
|
|
|
|
|
|
@bp.route('/show/<int:id>')
|
|
|
|
@ -61,7 +64,8 @@ def post_show(id):
|
|
|
|
|
|
|
|
|
|
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({'tags': tag.content}, url_for('.posts'))
|
|
|
|
|
# tag.endpoint = query_replace(dict(**session_rating(), tags=tag.content), url_for('.posts'))
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
for comment in post.comments:
|
|
|
|
|
comment.editform = CommentForm(id=comment.id, content=comment.content)
|
|
|
|
@ -82,12 +86,6 @@ def post_show(id):
|
|
|
|
|
comment_form=CommentForm(post_id=post.id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# from yadc.bp import manage
|
|
|
|
|
# @bp.route('/comment', methods=['POST'])
|
|
|
|
|
# @login_required
|
|
|
|
|
# def comment():
|
|
|
|
|
# return manage.modify_comment()
|
|
|
|
|
|
|
|
|
|
@bp.route('/comment', methods=['POST'])
|
|
|
|
|
@login_required
|
|
|
|
|
def comment():
|
|
|
|
@ -120,11 +118,6 @@ def comment():
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('main.posts'))
|
|
|
|
|
|
|
|
|
|
# @bp.route('/editpost', methods=['POST'])
|
|
|
|
|
# @login_required
|
|
|
|
|
# def editpost():
|
|
|
|
|
# return manage.modify_post()
|
|
|
|
|
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST'])
|
|
|
|
|
@login_required
|
|
|
|
|
def upload():
|
|
|
|
|