本文整理汇总了Python中app.models.Category.urlify方法的典型用法代码示例。如果您正苦于以下问题:Python Category.urlify方法的具体用法?Python Category.urlify怎么用?Python Category.urlify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.urlify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import urlify [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: put
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import urlify [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)