本文整理汇总了Python中forms.CategoryForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm.validate方法的具体用法?Python CategoryForm.validate怎么用?Python CategoryForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.CategoryForm
的用法示例。
在下文中一共展示了CategoryForm.validate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def post(self):
form = CategoryForm()
if form.is_submitted():
try:
if not form.validate():
raise Exception(_('ERROR_INVALID_SUBMISSION'))
category = Category.create()
if not form.slug.data:
form.slug.data = form.name.data
form.slug.data = Category.urlify(form.slug.data)
form.populate_obj(category)
category.save()
return render_view(url_for('CategoriesView:put', id=category.id),
message=_('CATEGORY_CREATE_SUCESS'),
redirect=True)
except Exception as e:
flash(e.message, 'error')
return render_view('admin/categories/add.html', form=form)
示例2: category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def category():
form = CategoryForm(formdata=request.form or None)
if request.method == 'POST':
if request.form and form.validate():
c = Category(name=form.name.data, shortName=form.shortName.data)
db.session.add(c)
db.session.commit()
return redirect(url_for('category'))
else:
flash('There was an error with your input: %s' % form.errors)
return redirect(url_for('category'))
else:
categories = Category.query.all()
return render_template('category.html', categories=categories, form=form)
示例3: add_cat
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def add_cat():
print (str(session['email']),'is on add_cat')
form = CategoryForm()
if request.method == 'POST':
if form.validate() == False:
return render_template('addcat.html', form=form)
else:
newcat = Categories(form.name.data, session['email'])
db_session.add(newcat)
db_session.commit()
flash('You created a new category.')
print (str(session['email']),'has successfully<BR>added a new category')
return redirect(url_for('home'))
elif request.method == 'GET':
print (str(session['email']),'is still on add_cat')
return render_template('addcat.html', form=form)
示例4: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def add_category():
"""Saves the new item and redirects to confirmation page."""
if needs_login():
return redirect(url_for('oauth2callback'))
form = CategoryForm(request.form)
if not form.validate():
return render_template('new_category.html', form=form)
category = models.Category(form.name.data)
db.session.add(category)
db.session.commit()
return render_template('generic.html',
title="Category Added",
description="%s has been added." % category.name,
redirect_to_index=True)
示例5: category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def category():
if not check_permission(current_user, 'admin'):
flash('你没有权限')
return redirect(url_for('Common.index'))
category_form = CategoryForm(request.form)
if category_form.validate():
c = Category(category_form.category_name.data)
c.save()
kwargs = dict(
category_form=category_form,
categorys=Category.query.all(),
category_update_form=CategoryUpdateForm(),
)
return render_template('admin/category.html', **kwargs)
示例6: editCategory
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def editCategory(category_id):
'''
Edit a category, requires to be logged and checks if the user is the
category owner in the html rendered file.
category_id is the id of the category to be edited.
Returns a redirect to show categories after edition in case of POST or the
edit category html page in case of GET.
'''
cat = Category.query.filter_by(id=category_id).first()
form = CategoryForm(request.form)
if request.method == 'POST' and form.validate():
cat.name = request.form['name']
db.session.commit()
flash("Category updated")
return redirect(url_for('showCategories'))
else:
return render_template('edit_category.html', cat=cat, form=form)
示例7: newCategory
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def newCategory():
'''
Add a category, requires to be logged and makes the user the category
owner.
Returns a redirect to show categories after adding the category in case of
POST or the add category html page in case of GET.
'''
form = CategoryForm(request.form)
if request.method == 'POST' and form.validate():
newCategory = Category(
name=form.name.data,
username=session['username'])
db.session.add(newCategory)
db.session.commit()
flash("New category created")
return redirect(url_for('showCategories'))
else:
return render_template('new_category.html', form=form)
示例8: create_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def create_category():
if 'email' not in session:
return redirect(url_for('home'))
form = CategoryForm()
if request.method == 'POST':
if form.validate() == False:
return render_template('create_category.html', form=form)
else:
newCategory = Category(form)
db.session.add(newCategory)
db.session.commit()
flash('Category created')
return redirect(url_for('create_category'))
elif request.method == 'GET':
return render_template('create_category.html', form=form)
示例9: put
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def put(self, id):
category = Category.get_by_id(id)
if category is None:
return render_view(url_for('CategoriesView:index'),
status=False,
redirect=True,
message=_('CATEGORY_NOT_FOUND'))
if not category.can_edit():
abort(401)
form = CategoryForm(category=category)
if form.is_submitted():
try:
if not form.validate():
raise Exception(_('ERROR_INVALID_SUBMISSION'))
if not form.slug.data:
form.slug.data = form.name.data
if category.slug != form.slug.data:
form.slug.data = Category.urlify(form.slug.data)
form.populate_obj(category)
category.save()
return render_view(url_for('CategoriesView:put', id=category.id),
message=_('CATEGORY_SAVE_SUCCESS'),
redirect=True)
except Exception as e:
flash(e.message, 'error')
return render_view('admin/categories/edit.html',
form=form,
category=category)
示例10: edit_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import validate [as 别名]
def edit_category(category_id):
if 'email' not in session:
return redirect(url_for('home'))
categoryByID = Category.query.filter_by(id=category_id).first_or_404()
show_category = CategoryForm()
show_category.setFormContentFromCategory(categoryByID)
if request.method == 'POST':
show_category = CategoryForm()
if show_category.validate() == False:
flash('Please fill out everything')
return render_template('edit_category.html', show_category=show_category, categoryByID = categoryByID)
else:
categoryByID.updateCategory(show_category)
db.session.add(categoryByID)
db.session.commit()
return redirect(url_for('admin_dashboard'))
elif request.method == 'GET':
return render_template('edit_category.html', show_category=show_category, categoryByID = categoryByID)