From a87297f968b731956dcc71361a408b21a30cdcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C5=BE=C3=ADlek?= Date: Thu, 14 May 2020 16:51:40 +0200 Subject: [PATCH] API - don't show unapproved + messages de-debug --- yadc/bp/manage.py | 39 ++++++++++++++++++++++++++------------- yadc/bp/post.py | 20 +++++++++++++------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/yadc/bp/manage.py b/yadc/bp/manage.py index de7b58b..8b08a05 100644 --- a/yadc/bp/manage.py +++ b/yadc/bp/manage.py @@ -97,7 +97,8 @@ def modify_user(): if form.op_level.data: el.op_level = form.op_level.data db.session.commit() - flash('New {} has been created.'.format(str(el))) + #flash('New {} has been created.'.format(str(el))) + flash('New user has been created.') else: el = User.query.get(form.id.data) @@ -112,7 +113,8 @@ def modify_user(): db.session.delete(el) db.session.commit() - flash('{} deleted.'.format(str(el))) + #flash('{} deleted.'.format(str(el))) + flash('User deleted.') elif form.edit.data: # if form.username.data: el.username = form.username.data @@ -122,7 +124,8 @@ def modify_user(): if form.op_level.raw_data and form.op_level.data: el.op_level = form.op_level.data db.session.commit() - flash('Changes to {} have been applied.'.format(str(el))) + #flash('Changes to {} have been applied.'.format(str(el))) + flash('Changes to user have been applied.') flasherrors(form) return redirect(url_for('.manage_users')) @@ -146,7 +149,8 @@ def modify_post(): el.remove_image_files() db.session.delete(el) db.session.commit() - flash('{} deleted.'.format(str(el))) + #flash('{} deleted.'.format(str(el))) + flash('Post deleted.') elif form.edit.data: if form.rating.raw_data and form.rating.data: el.rating = form.rating.data @@ -163,7 +167,8 @@ def modify_post(): el.tags = tags db.session.commit() - flash('Changes to {} have been applied.'.format(str(el))) + #flash('Changes to {} have been applied.'.format(str(el))) + flash('Changes to post have been applied.') elif form.approve.data: if not current_user.is_moderator: @@ -173,7 +178,8 @@ def modify_post(): el.approver = current_user db.session.commit() - flash('Approved post {}.'.format(str(el))) + #flash('Approved post {}.'.format(str(el))) + flash('Post approved.') # redirect(url_for('post.post_show', id=el.id)) flasherrors(form) @@ -198,21 +204,24 @@ def modify_tag(): if form.category.raw_data and form.category.data: el.category = form.category.data db.session.commit() - flash('New {} has been created.'.format(str(el))) + #flash('New {} has been created.'.format(str(el))) + flash('New tag has been created.') else: el = Tag.query.get(form.id.data) if form.delete.data: db.session.delete(el) db.session.commit() - flash('{} deleted.'.format(str(el))) + #flash('{} deleted.'.format(str(el))) + flash('Tag deleted.') elif form.edit.data: # if form.content.data: el.content = form.content.data if form.category.raw_data and form.category.data: el.category = form.category.data db.session.commit() - flash('Changes to {} have been applied.'.format(str(el))) + #flash('Changes to {} have been applied.'.format(str(el))) + flash('Changes to tag have been applied.') flasherrors(form) return redirect(url_for('.manage_tags')) @@ -233,7 +242,8 @@ def modify_comment(): if form.delete.data: db.session.delete(el) db.session.commit() - flash('{} deleted.'.format(str(el))) + #flash('{} deleted.'.format(str(el))) + flash('Comment deleted.') elif form.edit.data: # if form.rating.raw_data and form.rating.data: el.rating = form.rating.data @@ -241,21 +251,24 @@ def modify_comment(): # if form.source.raw_data: el.source = form.source.data # db.session.commit() - flash('Changes to {} have been applied.'.format(str(el))) + #flash('Changes to {} have been applied.'.format(str(el))) + flash('Changes to comment have been applied.') elif form.ban.data: el.ban_reason = form.ban_reason.data el.banned = True db.session.commit() - flash('Comment {} has been banned.'.format(str(el))) + #flash('Comment {} has been banned.'.format(str(el))) + flash('Comment has been banned.') elif form.unban.data: el.ban_reason = None el.banned = False db.session.commit() - flash('Comment {} has been unbanned.'.format(str(el))) + #flash('Comment {} has been unbanned.'.format(str(el))) + flash('Comment has been unbanned.') flasherrors(form) if form.referer.data == 'post_show': diff --git a/yadc/bp/post.py b/yadc/bp/post.py index 2009ba8..be85603 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -111,7 +111,8 @@ def comment(): db.session.add(el) db.session.commit() - flash('Successfully submitted {}.'.format(str(el))) + #flash('Successfully submitted {}.'.format(str(el))) + flash('Comment successfully submitted.') return redirect(url_for('post.post_show', id=form.post_id.data)) else: el = Comment.query.filter_by(id=form.id.data).first() @@ -124,12 +125,14 @@ def comment(): if form.delete.data: db.session.delete(el) db.session.commit() - flash('{} deleted.'.format(str(el))) + #flash('{} deleted.'.format(str(el))) + flash('Comment deleted.') elif form.edit.data: if form.content.raw_data and form.content.data: el.content = form.content.data.strip() db.session.commit() - flash('Changes to {} have been applied.'.format(str(el))) + #flash('Changes to {} have been applied.'.format(str(el))) + flash('Changes to comment have been applied.') elif form.ban.data: if not current_user.is_moderator: @@ -139,7 +142,8 @@ def comment(): el.deleted = True db.session.commit() - flash('Comment {} has been banned.'.format(str(el))) + #flash('Comment {} has been banned.'.format(str(el))) + flash('Comment has been banned.') elif form.unban.data: if not current_user.is_moderator: @@ -149,7 +153,8 @@ def comment(): el.deleted = False db.session.commit() - flash('Comment {} has been unbanned.'.format(str(el))) + #flash('Comment {} has been unbanned.'.format(str(el))) + flash('Comment has been unbanned.') return redirect(url_for('post.post_show', id=el.post_id)) @@ -175,7 +180,8 @@ def upload(): db.session.add(post) db.session.commit() - flash('Successfully submitted {}.'.format(str(post))) + #flash('Successfully submitted {}.'.format(str(post))) + flash('Upload successfully submitted.') return redirect(url_for('.posts')) @@ -212,7 +218,7 @@ def posts_api(): 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)) # posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created.desc()) - posts_query = posts_query.order_by(Post.created.desc()) + posts_query = posts_query.filter_by(status=POST_STATUS.active).order_by(Post.created.desc()) posts = posts_query.paginate(int(request.args.get('page', 0))+1, int(request.args.get('limit') or current_app.config.get('POSTS_PER_PAGE')))