本文整理汇总了Python中app.models.Category.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Category.delete方法的具体用法?Python Category.delete怎么用?Python Category.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import delete [as 别名]
def delete(self, id):
category = Category.get_by_id(id)
try:
if category is None:
raise Exception(_('CATEGORY_NOT_FOUND'))
if not category.can_edit():
abort(401)
if not Category.transfer_posts(category):
raise Exception(_('CATEGORY_TRANSFER_POSTS_FAILED'))
name = category.name
Category.delete(category.id)
flash(_('CATEGORY_REMOVE_SUCCESS', name=name))
except Exception as e:
flash(e.message, 'error')
return render_view(url_for('CategoriesView:index'),
redirect=True)
示例2: delete
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import delete [as 别名]
def delete(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)
try:
if not Category.transfer_posts(category):
return util.redirect_json_or_html(
url_for("CategoriesView:index"), "category", gettext("Sorry, the last category can not be removed")
)
name = category.name
Category.delete(category.id)
flash(gettext('The category "%(name)s" was removed', name=name))
except:
return util.redirect_json_or_html(
url_for("CategoriesView:index"), "category", gettext("Error while removing the category")
)
return util.redirect_json_or_html(url_for("CategoriesView:index"), "category")