コード例 #1
0
ファイル: views.py プロジェクト: ScarecrowFu/testflaskblog
def save_category_to_article():
    category_name = request.form.get('categoryname')
    category_description = request.form.get('categorydescription')

    if(category_name != None and category_description != None and category_name !="" and category_description != ""):
        category = Category.check_by_name(category_name)
        if(category is None):
            category = Category(name=category_name,description=category_description)
            print("111")
            try:
                db.session.add(category)
                db.session.commit()
            except:
                flash("save_category Database error!")
    return json.dumps({"id":category.id,"categoryname":category.name,"categorydescription":category.description})
コード例 #2
0
ファイル: views.py プロジェクト: ScarecrowFu/testflaskblog
def add_category():
    categoryform = CategoryForm()

    if categoryform.validate_on_submit():
        category_name = request.form.get('name')
        category_description = request.form.get('description')
        if(category_name != None and category_description != None and category_name !="" and category_description != ""):
            category = Category.check_by_name(category_name)
            if(category is None):
                category = Category(name=category_name,description=category_description)
            else:
                flash("category:%s is already exit" % category)
            try:
                db.session.add(category)
                db.session.commit()
            except:
                flash("add_category Database error!")
                return render_template("admin/addcategory.html",categoryform=categoryform)
        return redirect(url_for('list_category'))
    return render_template("admin/addcategory.html",categoryform=categoryform)