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


Python Page.current_revision方法代码示例

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


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

示例1: edit

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import current_revision [as 别名]
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                # it's a new page
                page = Page()

                page.name = form.cleaned_data['name']

                page.user = request.user
                page.created_on = datetime.now()
                page.save()

                page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page)
                page_revision.save()

                page.current_revision = page_revision
                page.save()

            else:
                # it's an edit on an old page

                page.name = form.cleaned_data['name']

                revision_count = PageRevision.objects.filter(revision_for = page).count()
                new_rev = revision_count + 1
                page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page, revision_num = new_rev)
                page_revision.save()

                page.current_revision = page_revision
                page.modified_on = datetime.now()
                page.user = request.user
                page.save()
            
            return HttpResponseRedirect('../../%s/' % page.name)
    else:
        if page:
            page_dict = page.__dict__
            # we have phased out page.content,
            # instead page will be a reference to current revision content.
            # but for the purposes of the form, we'll emulate it (ugly hack!)
            page_dict['content'] = page.current_revision.content
            form = PageForm(initial=page_dict)
        else:
            form = PageForm(initial={'name': name})

    context = RequestContext(request)
    return render_to_response('wiki/edit.html', {'form': form}, context)
开发者ID:localhorse,项目名称:django-nowiki,代码行数:57,代码来源:views.py

示例2: edit_page

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import current_revision [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.current_revision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。