Пример #1
0
def ban_profile(profile_id):
    form = BanForm()
    if form.validate_on_submit():
        reports = Report.query.filter_by(profile_id=profile_id).all()
        profile = User.query.filter_by(id=profile_id).first_or_404()
        profile.banned = 1
        profile.ban_reason = form.reason.data
        for report in reports:
            db.session.delete(report)
        db.session.commit()
        flash("Case resolved")
        return redirect(request.referrer)
    return redirect(url_for('index'))
Пример #2
0
def ban_comment(comment_id):
    form = BanForm()
    if form.validate_on_submit():
        reports = Report.query.filter_by(comment_id=comment_id).all()
        comment = Comment.query.filter_by(id=comment_id).first_or_404()
        comment.banned = 1
        comment.ban_reason = form.reason.data
        comment.author.demerits += 1
        for report in reports:
            db.session.delete(report)
        db.session.commit()
        flash("Case resolved")
        return redirect(request.referrer)
Пример #3
0
def ban_post(post_id):
    form = BanForm()
    if form.validate_on_submit():
        reports = Report.query.filter_by(post_id=post_id).all()
        post = Post.query.filter_by(id=post_id).first_or_404()
        post.banned = 1
        post.ban_reason = form.reason.data
        post.author.upvotes -= post.votes
        post.author.demerits += 1
        assign_badge(post.author)
        for report in reports:
            db.session.delete(report)
        db.session.commit()
        flash("Case resolved")
        return redirect(request.referrer)
Пример #4
0
def reported_users():
    form0 = SearchProfileForm()
    form = EmptyForm()
    form2 = BanForm()
    if current_user.id == 1:
        page = request.args.get('page', 1, type=int)
        users = User.query.filter(User.reports_on_me != None).paginate(
            page, app.config['POSTS_PER_PAGE'], False)
        next_url = url_for('reported_users', page=users.next_num) \
            if users.has_next else None
        prev_url = url_for('reported_users', page=users.prev_num) \
            if users.has_prev else None
        return render_template('reported_users.html',
                               title='Reported Users',
                               badge_colour=badge_colour,
                               users=users.items,
                               form=form,
                               form2=form2,
                               next_url=next_url,
                               prev_url=prev_url,
                               form0=form0)
    return render_template('admin_restricted.html')
Пример #5
0
def reported_comments():
    form0 = SearchProfileForm()
    form = EmptyForm()
    form2 = BanForm()
    if current_user.id == 1:
        page = request.args.get('page', 1, type=int)
        comments = Comment.query.filter(Comment.reports != None).paginate(
            page, app.config['POSTS_PER_PAGE'], False)
        next_url = url_for('reported_cases', page=comments.next_num) \
            if comments.has_next else None
        prev_url = url_for('reported_cases', page=comments.prev_num) \
            if comments.has_prev else None
        return render_template('reported_comments.html',
                               title='Reported Posts',
                               comments=comments.items,
                               form=form,
                               form2=form2,
                               form0=form0,
                               badge_colour=badge_colour,
                               next_url=next_url,
                               prev_url=prev_url)
    return render_template('admin_restricted.html')
Пример #6
0
def user(username):
    form0 = SearchProfileForm()
    form = EmptyForm()  #Follow/Unfollow button
    form2 = BanForm()
    user = User.query.filter_by(username=username).first_or_404()
    page = request.args.get('page', 1, type=int)
    posts = user.own_posts().paginate(page, app.config['POSTS_PER_PAGE'],
                                      False)
    next_url = url_for('user', username=user.username, page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('user', username=user.username, page=posts.prev_num) \
        if posts.has_prev else None
    if user.banned and current_user.id != 1:
        return render_template('banned.html')
    return render_template('user.html',
                           user=user,
                           form=form,
                           form2=form2,
                           form0=form0,
                           posts=posts.items,
                           upvote=Upvote,
                           badge_colour=badge_colour,
                           next_url=next_url,
                           prev_url=prev_url)