Exemplo n.º 1
0
def delete_post(post_id):
    post = Post.query.get_or_404(post_id)
    db.session.delete(post)
    db.session.commit()
    flash('文章删除成功', 'success')

    return redirect_back()
Exemplo n.º 2
0
def change_theme(theme_name):
    if theme_name not in current_app.config['BLUELOG_THEMES'].keys():
        abort(404)

    response = make_response(redirect_back())
    response.set_cookie('theme', theme_name, max_age=30 * 24 * 60 * 60)

    return response
Exemplo n.º 3
0
def delete_category(category_id):
    # 找到要删除的分类
    category = Category.query.get_or_404(category_id)
    # 找到此分类包含的所有文章
    # posts = category.posts
    # # 把属于此分类的文章转移到默认分类下
    # default = Category.query.first()
    # default.posts.extend(posts)
    # db.session.delete(category)
    # db.session.commit()
    category.delete()

    return redirect_back()
Exemplo n.º 4
0
def set_comment(post_id):
    """
    设置文章是否可以评论
    :param post_id: 文章id
    :return:
    """
    # 查找相应文章
    post = Post.query.get_or_404(post_id)
    # 设置评论开关
    if post.can_comment is True:
        print("can_comment: True")
        post.can_comment = False
        flash('评论关闭', 'success')
    else:
        print('can_comment: false')
        post.can_comment = True
        flash('评论开启', 'success')
    db.session.commit()
    return redirect_back()
Exemplo n.º 5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('blog.index'))
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        remember = form.remember.data
        user = Admin.query.filter_by(username=username).first()
        if not user:
            flash('用户名和密码不匹配', 'warning')
            return redirect(url_for('auth.login'))
        if user.validate_password(password):
            # 表示验证通过
            login_user(user, remember)
            flash('%s, 登陆成功, 欢迎回来' % username, 'info')
            return redirect_back()
        else:
            # 验证不通过
            flash('用户名和密码不匹配', 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 6
0
def approve_comment(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    comment.reviewed = True
    db.session.commit()
    flash('评论审核通过', 'success')
    return redirect_back()
Exemplo n.º 7
0
def delete_comment(comment_id):
    comment = Comment.query.get(comment_id)
    db.session.delete(comment)
    db.session.commit()
    flash('删除评论成功', 'info')
    return redirect_back()
Exemplo n.º 8
0
def logout():
    logout_user()
    flash('Logout success.', 'info')
    return redirect_back()