diff --git a/app/main/views.py b/app/main/views.py index c14c365..50b2d67 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -215,3 +215,40 @@ def show_followed(): resp = make_response(redirect(url_for('.index'))) resp.set_cookie('show_followed', '1', max_age=30*24*60*60) # lasts 30 days return resp + + +@main.route('/moderate') +@login_required +@permission_required(Permission.MODERATE) +def moderate(): + page = request.args.get('page', 1, type=int) + pagination = Comment.query.order_by(Comment.timestamp.desc()).paginate( + page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'], + error_out=False) + comments = pagination.items + return render_template('moderate.html', comments=comments, + pagination=pagination, page=page) + + +@main.route('/moderate/enable/') +@login_required +@permission_required(Permission.MODERATE) +def moderate_enable(id): + comment = Comment.query.get_or_404(id) + comment.disabled = False + db.session.add(comment) + db.session.commit() + return redirect(url_for('.moderate', + page=request.args.get('page', 1, type=int))) + + +@main.route('/moderate/disable/') +@login_required +@permission_required(Permission.MODERATE) +def moderate_disable(id): + comment = Comment.query.get_or_404(id) + comment.disabled = True + db.session.add(comment) + db.session.commit() + return redirect(url_for('.moderate', + page=request.args.get('page', 1, type=int))) diff --git a/app/templates/_comments.html b/app/templates/_comments.html index 73ee65d..caaf090 100644 --- a/app/templates/_comments.html +++ b/app/templates/_comments.html @@ -9,13 +9,26 @@
{{ moment(comment.timestamp).fromNow() }}
-
- {% if comment.body_html %} - {{ comment.body_html | safe }} - {% else %} - {{ comment.body }} +
+ {% if comment.disabled %} +

This comment has been disabled by a moderator.

+ {% endif %} + {% if moderate or not comment.disabled %} + {% if comment.body_html %} + {{ comment.body_html | safe }} + {% else %} + {{ comment.body }} + {% endif %} {% endif %}
+ {% if moderate %} +
+ {% if comment.disabled %} + Enable + {% else %} + Disable + {% endif %} + {% endif %}
{% endfor %} diff --git a/app/templates/base.html b/app/templates/base.html index 560c802..0d5aec9 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -30,6 +30,9 @@ {% endif %}