diff --git a/yadc/bp/auth.py b/yadc/bp/auth.py index df9ab24..c1f202d 100644 --- a/yadc/bp/auth.py +++ b/yadc/bp/auth.py @@ -64,7 +64,7 @@ def register(): if fl.current_user.is_authenticated: return redirect(url_for('main.index')) - if not current_app.config.get('ALLOW_REGISTER'): + if current_app.config.get('REGISTER_DISABLED'): flash('Registrations are disabled for now.') return redirect(url_for('main.index')) diff --git a/yadc/bp/post.py b/yadc/bp/post.py index bc3dd4b..ce6e454 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -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/') @@ -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) @@ -78,15 +82,9 @@ def post_show(id): tags=" ".join([t.content for t in post.tags]), rating=post.rating, status=post.status - ), + ), 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 @@ -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(): diff --git a/yadc/config.def.py b/yadc/config.def.py index 30267ca..9dcce64 100644 --- a/yadc/config.def.py +++ b/yadc/config.def.py @@ -1,6 +1,6 @@ INSTANCE_NAME = 'Darkne.su' -ALLOW_REGISTER = False +REGISTER_DISABLED = False SECRET_KEY = '' # SQLALCHEMY_ECHO = True diff --git a/yadc/templates/layout/base.html b/yadc/templates/layout/base.html index c4280ba..2c2a465 100644 --- a/yadc/templates/layout/base.html +++ b/yadc/templates/layout/base.html @@ -16,8 +16,16 @@ {{ config.get('INSTANCE_NAME') }}