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


Python PageForm.validate方法代码示例

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


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

示例1: PageHandler

# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import validate [as 别名]
class PageHandler(BaseHandler):
    """Manage individual pages"""
    
    @admin_required
    def get(self, page_id=None, **kwargs):
        """Return a page to edit or an empty form to create"""
        template = 'admin/page/new.html'
        context = {
            'form': self.form,
        }
        # render edit
        if page_id is not None:
            page = Page.get_by_id(page_id)
            if page:
                self.form = PageForm(obj=page)
                context.update({ 'form': self.form })
                template = 'admin/page/edit.html'
            else:
                return redirect('admin/page/')
        # render new
        return self.render_response(template, **context)
    
    @admin_required
    def post(self, page_id=None, **kwargs):
        """Handle submitted form data"""
        # validate form
        if self.form.validate():
            title = self.form.title.data
            content = self.form.content.data
            live = self.form.live.data
            language = self.form.language.data
            # saving edited
            if page_id:
                page = Page.get_by_id(page_id)
                page.title = title
                page.content = content
                page.live = live
                page.language = language
            # creating new
            else:
                page = Page(title=title, content=content, live=live, language=language)
            if page.put():
                return redirect('admin/page')
        return self.get(**kwargs)
    
    @cached_property
    def form(self):
        """Form instance as cached_property"""
        return PageForm(self.request)
开发者ID:tresacton,项目名称:gae-shop,代码行数:51,代码来源:handlers.py

示例2: save_page

# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import validate [as 别名]
def save_page(page_id=None):
    """Save Page to database

    If page_id is None a new Page will be inserted in the database. Otherwise
    the existing Page will be updated.
    """
    message = 'Page updated'

    page_form = PageForm(request.form)

    if not page_form.validate():
        flash('ERROR: errors detected. Page NOT saved!', category='error')
        return edit_page(page_id=page_id, page_form=page_form)

    if page_id is None:
        page = Page(request.form['title'], request.form['content'])
        page.status_id = 1
        page.user_id = session['user_id']
        page.createdate = datetime.now()
    else:
        page = get_page(page_id)

    page_form.populate_obj(page)
    page.lastmoddate = datetime.now()

    # compile input to html
    page.compile(app.config['REPL_TAGS'])

    # update pubdate if page's pubdate is None and its status is set
    # to public
    if request.form['status'] == 'public' and \
           unicode(page.status) != 'public' and \
           page.pubdate is None:
        page.pubdate = datetime.now()

    page.status = get_status(request.form['status'])

    if page.slug is None:
        page.slug = slugify(page.title)

    if page_id is None:
        db_session.add(page)
        message = 'New page was successfully added'

    db_session.commit()

    flash(message)

    return redirect(url_for('edit_page', page_id=page.id))
开发者ID:jkossen,项目名称:imposter,代码行数:51,代码来源:admin.py

示例3: new_page

# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import validate [as 别名]
def new_page(site_id):
    site = Site.get_admin_or_404(site_id)
    form = PageForm(request.form, site=site)
    if request.method == 'POST':
        if form.validate():
            page = Page.new_page(site, form.name.data, form.url.data)
            new_url = url_for('editor', page_id=page.key().id())
            if request.is_xhr:
                return jsonify(dict(type='success', redirect=new_url))
            return redirect(new_url)
        elif request.is_xhr:
            return jsonify(dict(type='error', errors=render_template('form_errors.html', form=form)))
    if request.is_xhr:
        return render_template('page_creator.html', form=form, site=site)
    return render_template('new_page.html', form=form, site=site)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:17,代码来源:views.py

示例4: edit_page

# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import validate [as 别名]
def edit_page(page_id):
    page = Page.get_admin_or_404(page_id)
    form = PageForm(request.form, page)
    if request.method == 'POST':
        if form.validate():
            if form.data['url'] != page.url:
                page.queue_preview()
            page.name = form.name.data
            page.url = form.url.data
            page.preview_urls = [Link(url.data) for url in form.preview_urls]
            page.put()
            if request.is_xhr:
                return 'OK'
        elif request.is_xhr:
            return render_template('form_errors.html', form=form)
    if request.is_xhr:
        return render_template('page_editor.html', form=form, page=page)
    return render_template('edit_page.html', form=form, site=page.site, page=page)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:20,代码来源:views.py

示例5: new_site

# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import validate [as 别名]
def new_site():
    user = users.get_current_user()
    form = PageForm(request.form)
    if request.method == 'POST':
        if form.validate():
            site = Site(
                name = form.name.data,
                owner = user,
                users = [user],
                admins = [user],
            )
            site.put()
            page = Page.new_page(site, form.name.data, form.url.data)
            new_url = url_for('editor', page_id=page.key().id())
            if request.is_xhr:
                return jsonify(dict(type='success', redirect=new_url))
            else:
                return redirect(new_url)
        elif request.is_xhr:
            return jsonify(dict(type='error', errors=render_template('form_errors.html', form=form)))
    if request.is_xhr:
        return render_template('site_creator.html', form=form)
    return render_template('new_site.html', form=form)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:25,代码来源:views.py


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