本文整理汇总了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))
示例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)
示例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)
示例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)
示例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'))
示例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)
示例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)
示例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'))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)