當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.transfer_posts方法代碼示例

本文整理匯總了Python中models.Category.transfer_posts方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.transfer_posts方法的具體用法?Python Category.transfer_posts怎麽用?Python Category.transfer_posts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Category的用法示例。


在下文中一共展示了Category.transfer_posts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: transfer_post

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import transfer_posts [as 別名]
    def transfer_post(self):
        trans = TranferCatForm()
        if trans.validate_on_submit():
            cat_from = Category.get_by_id(trans.from_id.data)
            cat_to = Category.get_by_id(trans.to_id.data)
            
            if cat_from and cat_to:
                Category.transfer_posts(cat_from, cat_to)
                flash(gettext('The posts were transfered from %(from_name)s to %(to_name)s',
                    from_name=cat_from.name, to_name=cat_to.name))
            else:
                flash(gettext('Either category was not found'), 'error')
        else:
            flash(trans.get_errors(), 'error')

        return redirect(url_for('CategoriesView:index'))
開發者ID:Tibodef,項目名稱:PythonBlog,代碼行數:18,代碼來源:views.py

示例2: delete

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import transfer_posts [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')
開發者ID:Tibodef,項目名稱:PythonBlog,代碼行數:25,代碼來源:views.py


注:本文中的models.Category.transfer_posts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。