当前位置: 首页>>代码示例>>Python>>正文


Python CategoryForm.validate_on_submit方法代码示例

本文整理汇总了Python中forms.CategoryForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm.validate_on_submit方法的具体用法?Python CategoryForm.validate_on_submit怎么用?Python CategoryForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.CategoryForm的用法示例。


在下文中一共展示了CategoryForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: category_update

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def category_update(category_name):
    """Update category name and description in database"""
    if 'username' not in login_session:
        return redirect(url_for('login'))
    category = Category.query.filter(Category.name == category_name).first()
    if category.author_id != login_session['user_id']:
        return ""
    form = CategoryForm()
    if form.validate_on_submit():
        try:
            category.name = form.name.data
            category.description = form.description.data
            db_session.add(category)
            db_session.commit()
            return redirect(url_for('category_view',
                                    category_name=form.name.data))
        except IntegrityError:
            db_session.rollback()
            flash("Category name must be unique value")
        except Exception:
            db_session.rollback()
            flash("Database error encountered")
    flash_errors(form)
    return redirect(url_for('category_edit',
                            category_name=category_name))
开发者ID:vanadium23,项目名称:catalog-project,代码行数:27,代码来源:views.py

示例2: editCategory

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def editCategory(name):
    """Edit a named category or render a form.

    Args: A category name

    Returns: Edited category or render a form.
    """
    # Store caetgory and logged in user
    category = Category.query.filter_by(name=name).first_or_404()
    user = Users.query.filter_by(id=login_session["users_id"]).first_or_404()
    # Verify that the logged in user is creator or admin
    if category.users_id != login_session["users_id"] and not user.admin:
        flash(" You are not authorized to make that edit.")
        return redirect(url_for("category.showCategory", category_id=category_id))
    # Initiate the form.
    form = CategoryForm(obj=category)
    # On POST of a valid form, edit the category.
    if form.validate_on_submit():
        category.name = form.name.data
        category.description = form.description.data
        category.picture = form.picture.data
        db.session.add(category)
        db.session.commit()
        flash(" Category %s Successfully Edited" % category.name)
        return redirect(url_for("category.showCategory", name=category.name))
    else:
        return render_template("editCategory.html", form=form, category=category)
开发者ID:qgreg,项目名称:itemcatalog,代码行数:29,代码来源:views.py

示例3: put

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
    def put(self, id):
        category = Category.get_by_id(id)
        if category is None:
            flash(gettext('The category was not found'), 'error')
            return redirect(url_for('CategoriesView:index'))
        if not category.can_edit():
            abort(401)

        if request.method in ['POST', 'PUT']:
            form = CategoryForm()
            if form.validate_on_submit():
                try:
                    form.populate_obj(category)
                    category.save()
                    flash(gettext('Category was succesfully saved'))
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category')
                except:
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Error while updating the category'))
            else:
                if request.is_xhr:
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Invalid submission, please check the message below'))
                else:
                    flash(gettext('Invalid submission, please check the message below'), 'error')
        else:
            form = NewCategoryForm(category)
        return render_template('admin/categories/edit.html',
            title=gettext('Edit Category: %(name)s', name=category.name),
            form=form,
            category=category)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:31,代码来源:views.py

示例4: addcategory

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def addcategory():
    form = CategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.name.data,)
        db.session.add(category)
        db.session.commit()
        return redirect(url_for('admin.listcategory'))
    return render_template('/addcategory.html', form=form)
开发者ID:SuZhiBai,项目名称:flaskblog,代码行数:10,代码来源:views.py

示例5: editCategory

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def editCategory(cat_id):
    catForm = CategoryForm()
    cat = Category.query.get(cat_id)
    if catForm.validate_on_submit():
        cat.name = catForm.name.data
        cat.note=catForm.note.data
        db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
开发者ID:iredkoz,项目名称:testapp,代码行数:10,代码来源:views.py

示例6: editcategory

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def editcategory():
    form = CategoryForm()
    form.name.data = request.args.get('category_id')
    if form.validate_on_submit():
        category = Category.query.filter_by(name=form.name.data).first()
        category.name = form.name.data
        db.session.add(category)
        db.session.commit()
        return redirect(url_for('admin.listcategory'))
    return render_template('/addcategory.html', form=form)
开发者ID:SuZhiBai,项目名称:flaskblog,代码行数:12,代码来源:views.py

示例7: admin_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def admin_category():

    form = CategoryForm()
    if request.method == 'POST' and form.validate_on_submit():
        cat_name = form.cat_name.data.strip()
        cat_description = form.cat_description.data.strip()
        Category.save(cat_name, cat_description)
        categories = Category.query.all()
        return render_template('admin_categories.html', title='Admin', user=current_user, categories=categories)

    return render_template('admin_new_category.html', title='Admin', form=form, user=current_user)
开发者ID:FengNongtheWindCoder,项目名称:flaskblog,代码行数:13,代码来源:views.py

示例8: newCat

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def newCat():
    catForm = CategoryForm()
    name = catForm.name.data
    if catForm.validate_on_submit():
        if Category.query.filter_by(name=name).first():
            flash('Category already exists!','alert-danger')
        else:
            cat = Category(name=name, note = catForm.note.data)
            db.session.add(cat)
            db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
开发者ID:iredkoz,项目名称:testapp,代码行数:13,代码来源:views.py

示例9: new_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def new_category():
    form = CategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.name.data)
        try:
            category.put()
            flash(u"Example %s successfully saved." % category.name, "success")
            return redirect(url_for("list_categories"))
        except CapabilityDisabledError:
            flash(u"App Engine Datastore is currently in read-only mode.", "info")
            return redirect(url_for("list_categories"))
    return render_template("new_category.html", form=form)
开发者ID:cenzino,项目名称:vp-gae,代码行数:14,代码来源:views.py

示例10: admin_edit_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def admin_edit_category(cat_id):

    form = CategoryForm()
    if request.method == 'POST' and form.validate_on_submit():
        cat_name = form.cat_name.data.strip()
        cat_description = form.cat_description.data.strip()
        Category.update(cat_id, cat_name, cat_description)
        categories = Category.query.all()
        return render_template('admin_categories.html', title='Admin', user=current_user, categories=categories)
    else:
        category = Category.query.filter_by(cat_id=cat_id).first()
        form.cat_name.data = category.cat_name
        form.cat_description.data = category.cat_description
        return render_template('admin_edit_category.html', title='Admin', form=form, user=current_user)
开发者ID:FengNongtheWindCoder,项目名称:flaskblog,代码行数:16,代码来源:views.py

示例11: edit_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def edit_category(category_name):
    category = Category.get_by_key_name(category_name)
    form = CategoryForm(obj=category)

    if form.validate_on_submit():
        form.populate_obj(category)
        try:
            category.put()
            flash(u"Example %s successfully saved." % category.name, "success")
            return redirect(url_for("list_categories"))
        except CapabilityDisabledError:
            flash(u"App Engine Datastore is currently in read-only mode.", "info")
            return redirect(url_for("list_categories"))
    return render_template("edit_category.html", form=form, category_name=category.id)
开发者ID:cenzino,项目名称:vp-gae,代码行数:16,代码来源:views.py

示例12: add_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def add_category():
    form = CategoryForm()

    if form.validate_on_submit():
        category = Category(name = form.name.data)

        db.session.add(category)
        db.session.commit()

        flash("Poprawnie dodano kategorie")

        return redirect('admin/categories')

    return render_template('admin/add_category.html',
                            title='Nowa kategoria',
                            form=form)
开发者ID:zpidreamteam,项目名称:ZPI,代码行数:18,代码来源:admin_panel.py

示例13: add_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def add_category():

    error = None
    form = CategoryForm()

    if request.method == "POST":
        form = CategoryForm(request.form)
        if form.validate_on_submit():
            category = Category(name=form.name.data)
            db.session.add(category)
            db.session.commit()
        else:
            error = "Invalid username or password."

    categories = Category.query.all()

    return render_template("category.html", form=form, categories=categories, error=error)
开发者ID:Nerevarsoul,项目名称:bookmark,代码行数:19,代码来源:views.py

示例14: post

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
    def post(self):
        form = CategoryForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                try:
                    category = Category.create()
                    form.populate_obj(category)
                    category.save()

                    flash(gettext('Category succesfully created'))
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category')
                except:
                    flash(gettext('Error while creating the category'), 'error')
            else:
                flash(gettext('Invalid submission, please check the message below'), 'error')
        return render_template('admin/categories/add.html',
            title=gettext('Create Category'),
            form=form)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:20,代码来源:views.py

示例15: addCategory

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate_on_submit [as 别名]
def addCategory():
    """Add a new category.

    Returns: Redirect Home.
    """
    # Initiate the form.
    form = CategoryForm()
    # On POST of a valid form, add the new category.
    if form.validate_on_submit():
        category = Category(form.name.data, form.description.data, form.picture.data, login_session["users_id"])
        db.session.add(category)
        db.session.commit()
        flash("New Category %s Successfully Created" % category.name)
        current_app.logger.info("New Category %s Created on %s" % (category.name, str(category.dateCreated)))
        return redirect(url_for("category.showHome"))
    else:
        # Render the form to add the category.
        return render_template("newCategory.html", form=form)
开发者ID:qgreg,项目名称:itemcatalog,代码行数:20,代码来源:views.py


注:本文中的forms.CategoryForm.validate_on_submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。