当前位置: 首页>>代码示例>>Python>>正文


Python Category.transfer_posts方法代码示例

本文整理汇总了Python中app.models.Category.transfer_posts方法的典型用法代码示例。如果您正苦于以下问题:Python Category.transfer_posts方法的具体用法?Python Category.transfer_posts怎么用?Python Category.transfer_posts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.models.Category的用法示例。


在下文中一共展示了Category.transfer_posts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: transfer_post

# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import transfer_posts [as 别名]
    def transfer_post(self):

        form = TranferForm()

        if form.is_submitted():
            try:
                if not form.validate():
                    raise Exception(_('ERROR_INVALID_SUBMISSION'))

                cat_from = Category.get_by_id(form.from_id.data)
                cat_to = Category.get_by_id(form.to_id.data)

                if not cat_from or not cat_to:
                    raise Exception(_('CATEGORY_TRANSFER_POSTS_CHECK_FAILED'))

                Category.transfer_posts(cat_from, cat_to)

                message = _('CATEGORY_TRANSFER_POSTS_SUCCESS',
                            from_name=cat_from.name,
                            to_name=cat_to.name)

                return render_view(url_for('CategoriesView:index'),
                                   message=message,
                                   redirect=True)
            except Exception as e:
                flash(e.message, 'error')

        return render_view('admin/categories/transfer.html',
                           form=form)
开发者ID:jctt1983,项目名称:PythonBlog,代码行数:31,代码来源:index.py

示例2: transfer_post

# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.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:,项目名称:,代码行数:23,代码来源:

示例3: delete

# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import transfer_posts [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)
开发者ID:jctt1983,项目名称:PythonBlog,代码行数:24,代码来源:index.py

示例4: delete

# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.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:,项目名称:,代码行数:25,代码来源:


注:本文中的app.models.Category.transfer_posts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。