Exemple #1
0
def add_type():
    if request.method == 'GET':
        return render_template('/back/category_add.html')
    if request.method == 'POST':
        atype = request.form.get('atype')
        if not atype:
            error = '警告!请填写分类信息'
            return render_template('/back/category_add.html', error=error)
        art_type = ArticleType()
        art_type.t_name = atype
        db.session.add(art_type)
        db.session.commit()
        return redirect(url_for('back.a_type'))
Exemple #2
0
def add_type():
    if request.method == 'GET':
        return render_template('back/category_add.html')
    if request.method == 'POST':
        atype = request.form.get('atype')
        if atype:
            # 保存分类
            art_type = ArticleType()
            art_type.t_name = atype
            art_type.save()
            return redirect(url_for('back.a_type'))
        else:
            error = '请填写分类信息!'
            return render_template('back/category_add.html', error=error)
Exemple #3
0
def update_category(id):
    if request.method == 'GET':
        categorys = ArticleType.query.get(id)
        return render_template('back/update-category.html',
                               categorys=categorys)
    if request.method == 'POST':
        ArticleType.id = request.view_args.get('id')
        type = ArticleType()
        if type.id == request.view_args.get('id'):
            del_article_type(type.id)
        type.id = id
        type.t_name = request.values.get('t_name')
        db.session.add(type)
        db.session.commit()
        return redirect(url_for('back.category'))
Exemple #4
0
def add_type():
    if request.method=='GET':
        user = User.query.filter(User.id == session['user_id']).first()
        return render_template('back/category_add.html',user=user)
    if request.method=='POST':
        atype=request.form.get('atype')
        if atype:
            art_type=ArticleType()
            art_type.t_name=atype
            db.session.add(art_type)
            db.session.commit()
            return redirect(url_for('back.a_type'))
            # return render_template('back/category_list.html',user=user)
        else:
            error='请填写分类信息'
            return render_template('back/category_add.html', error=error)
Exemple #5
0
def add_category():
    if request.method == 'GET':
        return render_template('back/add-category.html')
    if request.method == 'POST':
        atype = request.form.get('atype')
        if atype:
            # 保存分类信息
            art_type = ArticleType()
            art_type.t_name = atype
            db.session.add(art_type)
            db.session.commit()
            return redirect(url_for('back.a_type'))

        else:
            error = '请填写分类信息'
            return render_template('back/add-category.html')
Exemple #6
0
def add_type():
    if request.method == 'GET':
        return render_template('back/category_add.html')
    if request.method == 'POST':
        atype = request.form.get('atype')
        if atype:
            type1 = ArticleType.query.filter(
                ArticleType.t_name == atype).first()
            if type1:
                error = '文章分类已存在,请重新输入'
                return render_template('back/category_add.html', error=error)
            else:
                art_type = ArticleType()
                art_type.t_name = atype
                db.session.add(art_type)
                db.session.commit()
                return redirect(url_for('back.a_type'))

        else:
            error = '请填写分类信息'
            return render_template('back/category_add.html', error=error)