當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。