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


Python CategoryForm.populate_obj方法代码示例

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


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

示例1: put

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import populate_obj [as 别名]
    def put(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)

        if request.method in ['POST', 'PUT']:
            form = CategoryForm()
            if form.validate_on_submit():
                try:
                    form.populate_obj(category)
                    category.save()
                    flash(gettext('Category was succesfully saved'))
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category')
                except:
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Error while updating the category'))
            else:
                if request.is_xhr:
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Invalid submission, please check the message below'))
                else:
                    flash(gettext('Invalid submission, please check the message below'), 'error')
        else:
            form = NewCategoryForm(category)
        return render_template('admin/categories/edit.html',
            title=gettext('Edit Category: %(name)s', name=category.name),
            form=form,
            category=category)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:31,代码来源:views.py

示例2: post

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

示例3: categoryEdit

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import populate_obj [as 别名]
def categoryEdit(id):
    category = SpendingCategory.query.filter(SpendingCategory.id == id).one()

    form = CategoryForm(request.form, obj=category)
    if request.method == 'POST':
        form.populate_obj(category)
        db.session.merge(category)
        db.session.commit()

        flash('Category '+category.name+' updated.')

    return render_template('edit_category.html', f=form, obj=category)
开发者ID:vikin91,项目名称:euroInAFlask,代码行数:14,代码来源:euroInAFlask.py

示例4: edit_category

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import populate_obj [as 别名]
def edit_category(category_name):
    category = Category.get_by_key_name(category_name)
    form = CategoryForm(obj=category)

    if form.validate_on_submit():
        form.populate_obj(category)
        try:
            category.put()
            flash(u"Example %s successfully saved." % category.name, "success")
            return redirect(url_for("list_categories"))
        except CapabilityDisabledError:
            flash(u"App Engine Datastore is currently in read-only mode.", "info")
            return redirect(url_for("list_categories"))
    return render_template("edit_category.html", form=form, category_name=category.id)
开发者ID:cenzino,项目名称:vp-gae,代码行数:16,代码来源:views.py

示例5: post

# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import populate_obj [as 别名]
    def post(self):
        form = CategoryForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                try:
                    category = Category.create()
                    form.populate_obj(category)
                    category.save()

                    flash(gettext('Category succesfully created'))
                    return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category')
                except:
                    flash(gettext('Error while creating the category'), 'error')
            else:
                flash(gettext('Invalid submission, please check the message below'), 'error')
        return render_template('admin/categories/add.html',
            title=gettext('Create Category'),
            form=form)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:20,代码来源:views.py

示例6: put

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


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