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


Python Page.slug方法代码示例

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


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

示例1: show_pages

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import slug [as 别名]
def show_pages():
    if request.method == "POST" and g.site.domain == g.user:
        name = request.form['name']
        if name:
            p = Page()
            p.name = name
            p.slug = slugify(name)
            p.site = g.site.domain
            p.save()
            return redirect(url_for(".edit_page", slug=p.slug))
    pages = Page.objects(site=g.site.domain)
    return render_template('pages.html', pages=pages)
开发者ID:abal09,项目名称:samklang,代码行数:14,代码来源:pages.py

示例2: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import slug [as 别名]
    def post(self, slug=None):
        if slug:
            page = Page.gql("WHERE slug = :1", slug).get()
        else:
            page = Page()
        page.title = self.request.get('title')
        page.slug = self.request.get('slug')
        page.content = self.request.get('content')
        page.order_in_menu = int(self.request.get('order_in_menu'))

        page.put()

        self.redirect(page.get_url())
开发者ID:ibz,项目名称:nuages,代码行数:15,代码来源:admin.py

示例3: save_page

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import slug [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

示例4: edit_page

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import slug [as 别名]
def edit_page(request, page_slug=None, template_name='page/edit.html'):
    title = title_from_slug(page_slug)
    try:
        page = Page.objects.get(slug=page_slug)
    except Page.DoesNotExist:
        page = Page()

    if request.method == 'POST':
        revision = PageRevision(page=page, number=page.next_revision())
        form = PageRevisionForm(request.POST, instance=revision)

        if form.is_valid():
            # Save the page, in case it is new and because a revision requires a valid Page object
            page.title = title
            page.slug = page_slug
            page.save()

            # Save the revision
            new_revision = form.save(commit=False)
            new_revision.page = page
            new_revision.number = page.next_revision()
            new_revision.save()

            # Update the page's current revision now that the new revision has been persisted
            page.current_revision = new_revision
            page.save()

            return HttpResponseRedirect("/" + page_slug)
        else:
            print form.errors

    else:
        form = PageRevisionForm(instance=page.current_revision, initial={"comment": ""})

    context = {
        'title': title,
        'form': form.as_table(),
    }
    return render_to_response(template_name, RequestContext(request, context))
开发者ID:jsok,项目名称:django-iki-wiki,代码行数:41,代码来源:views.py


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