コード例 #1
0
ファイル: views.py プロジェクト: Tibodef/PythonBlog
    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'))
コード例 #2
0
ファイル: views.py プロジェクト: Tibodef/PythonBlog
    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')