本文整理汇总了Python中content.models.PageVersion类的典型用法代码示例。如果您正苦于以下问题:Python PageVersion类的具体用法?Python PageVersion怎么用?Python PageVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageVersion类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_page
def delete_page(request, slug, page_slug):
page = get_object_or_404(Page, project__slug=slug, slug=page_slug)
if page.deleted or not page.listed:
return http.HttpResponseForbidden(_("You can't delete this page"))
if not page.project.is_organizing(request.user) and not page.collaborative:
return http.HttpResponseForbidden(_("You can't delete this page"))
if request.method == "POST":
old_version = PageVersion(
title=page.title,
sub_header=page.sub_header,
content=page.content,
author=page.author,
date=page.last_update,
page=page,
)
old_version.save()
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
page.deleted = True
page.save()
messages.success(request, _("%s deleted!") % page.title)
return http.HttpResponseRedirect(
reverse("page_history", kwargs={"slug": page.project.slug, "page_slug": page.slug})
)
else:
return render_to_response(
"content/confirm_delete_page.html",
{"page": page, "project": page.project},
context_instance=RequestContext(request),
)
示例2: delete_page
def delete_page(request, slug, page_slug):
page = get_object_or_404(Page, project__slug=slug, slug=page_slug)
if page.deleted or not page.listed:
return http.HttpResponseForbidden(_("You can't delete this page"))
if not page.project.is_organizing(request.user) and not page.collaborative:
return http.HttpResponseForbidden(_("You can't delete this page"))
if request.method == 'POST':
redirect_url = request.POST.get('next_page', None)
old_version = PageVersion(title=page.title, sub_header=page.sub_header,
content=page.content, author=page.author, date=page.last_update,
page=page)
old_version.save()
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
page.deleted = True
page.save()
messages.success(request, _('%s deleted!') % page.title)
if redirect_url:
return http.HttpResponseRedirect(redirect_url)
return http.HttpResponseRedirect(reverse('page_history',
kwargs={'slug': page.project.slug, 'page_slug': page.slug}))
else:
context = {
'page': page,
'project': page.project,
}
referer = request.META.get('HTTP_REFERER', None)
if referer:
context['next_page'] = urlsplit(referer, 'http', False)[2]
return render_to_response('content/confirm_delete_page.html',
context, context_instance=RequestContext(request))
示例3: restore_version
def restore_version(request, slug, page_slug, version_id):
version = get_object_or_404(PageVersion, page__project__slug=slug, page__slug=page_slug, id=version_id)
page = version.page
if version.deleted:
return http.HttpResponseForbidden(_("You can't restore this page"))
if page.project.is_organizing(request.user):
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return http.HttpResponseForbidden(_("You can't edit this page"))
if request.method == "POST":
old_version = PageVersion(
title=page.title,
sub_header=page.sub_header,
content=page.content,
author=page.author,
date=page.last_update,
page=page,
deleted=page.deleted,
)
form = form_cls(request.POST, instance=page)
if form.is_valid():
page = form.save(commit=False)
page.deleted = False
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
if "show_preview" not in request.POST:
old_version.save()
page.save()
messages.success(request, _("%s restored!") % page.title)
return http.HttpResponseRedirect(reverse("page_show", kwargs={"slug": slug, "page_slug": page_slug}))
else:
messages.error(request, _("Please correct errors below."))
else:
page.title = version.title
page.content = version.content
form = form_cls(instance=page, initial={"minor_update": True})
return render_to_response(
"content/restore_version.html",
{
"form": form,
"page": page,
"version": version,
"project": page.project,
"preview": ("show_preview" in request.POST),
"is_challenge": (page.project.category == Project.CHALLENGE),
},
context_instance=RequestContext(request),
)
示例4: restore_version
def restore_version(request, slug, page_slug, version_id):
version = get_object_or_404(PageVersion, page__project__slug=slug,
page__slug=page_slug, id=version_id)
page = version.page
if not page.editable or version.deleted:
return http.HttpResponseForbidden(_("You can't edit this page"))
if page.project.is_organizing(request.user):
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return http.HttpResponseForbidden(_("You can't edit this page"))
preview = False
if request.method == 'POST':
old_version = PageVersion(title=page.title, content=page.content,
author=page.author, date=page.last_update, page=page,
deleted=page.deleted)
form = form_cls(request.POST, instance=page)
if form.is_valid():
page = form.save(commit=False)
page.deleted = False
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
if 'show_preview' in request.POST:
preview = True
page.content = bleach.clean(page.content,
tags=settings.RICH_ALLOWED_TAGS,
attributes=settings.RICH_ALLOWED_ATTRIBUTES,
styles=settings.RICH_ALLOWED_STYLES, strip=True)
else:
old_version.save()
page.save()
messages.success(request, _('%s restored!') % page.title)
return http.HttpResponseRedirect(reverse('page_show', kwargs={
'slug': slug,
'page_slug': page_slug,
}))
else:
messages.error(request, _('Please correct errors bellow.'))
else:
page.title = version.title
page.content = version.content
form = form_cls(instance=page)
return render_to_response('content/restore_version.html', {
'form': form,
'page': page,
'version': version,
'project': page.project,
'preview': preview,
}, context_instance=RequestContext(request))
示例5: edit_page
def edit_page(request, slug, page_slug):
page = get_object_or_404(Page, project__slug=slug, slug=page_slug)
if page.deleted:
return http.HttpResponseForbidden(_("You can't edit this page"))
if page.project.is_organizing(request.user):
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return http.HttpResponseForbidden(_("You can't edit this page"))
if request.method == "POST":
old_version = PageVersion(
title=page.title, content=page.content, author=page.author, date=page.last_update, page=page
)
form = form_cls(request.POST, instance=page)
if form.is_valid():
page = form.save(commit=False)
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
if "show_preview" not in request.POST:
old_version.save()
page.save()
messages.success(request, _("%s updated!") % page.title)
if form.cleaned_data.get("next_url", None):
return http.HttpResponseRedirect(form.cleaned_data.get("next_url"))
else:
return http.HttpResponseRedirect(
reverse("page_show", kwargs={"slug": slug, "page_slug": page_slug})
)
else:
messages.error(request, _("Please correct errors below."))
else:
initial = {"minor_update": True}
if request.GET.get("next_url", None):
initial["next_url"] = request.GET.get("next_url", None)
form = form_cls(instance=page, initial=initial)
context = {
"form": form,
"page": page,
"project": page.project,
"preview": ("show_preview" in request.POST),
"is_challenge": (page.project.category == Project.CHALLENGE),
}
return render_to_response("content/edit_page.html", context, context_instance=RequestContext(request))
示例6: restore_version
def restore_version(request, slug, page_slug, version_id):
version = get_object_or_404(PageVersion, page__project__slug=slug,
page__slug=page_slug, id=version_id)
page = version.page
if version.deleted:
return http.HttpResponseForbidden(_("You can't restore this page"))
if page.project.is_organizing(request.user):
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return http.HttpResponseForbidden(_("You can't edit this page"))
if request.method == 'POST':
old_version = PageVersion(title=page.title, sub_header=page.sub_header,
content=page.content, author=page.author, date=page.last_update,
page=page, deleted=page.deleted)
form = form_cls(request.POST, instance=page)
if form.is_valid():
page = form.save(commit=False)
page.deleted = False
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
if 'show_preview' not in request.POST:
old_version.save()
page.save()
messages.success(request, _('%s restored!') % page.title)
return http.HttpResponseRedirect(reverse('page_show', kwargs={
'slug': slug,
'page_slug': page_slug,
}))
else:
messages.error(request, _('Please correct errors below.'))
else:
page.title = version.title
page.content = version.content
form = form_cls(instance=page, initial={'minor_update': True})
return render_to_response('content/restore_version.html', {
'form': form,
'page': page,
'version': version,
'project': page.project,
'preview': ('show_preview' in request.POST),
'is_challenge': (page.project.category == Project.CHALLENGE),
}, context_instance=RequestContext(request))
示例7: restore_version
def restore_version(request, slug, page_slug, version_id):
version = get_object_or_404(PageVersion, page__project__slug=slug,
page__slug=page_slug, id=version_id)
page = version.page
if not page.editable or version.deleted:
return HttpResponseForbidden(_("You can't edit this page"))
if page.project.is_organizing(request.user):
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return HttpResponseForbidden(_("You can't edit this page"))
if request.method == 'POST':
old_version = PageVersion(title=page.title, content=page.content,
author=page.author, date=page.last_update, page=page, deleted=page.deleted)
form = form_cls(request.POST, instance=page)
if form.is_valid():
old_version.save()
page = form.save(commit=False)
page.deleted = False
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
page.save()
messages.success(request, _('%s restored!') % page.title)
return HttpResponseRedirect(reverse('page_show', kwargs={
'slug': slug,
'page_slug': page_slug,
}))
else:
messages.error(request,
_('There was a problem saving %s.' % page.title))
else:
page.title = version.title
page.content = version.content
form = form_cls(instance=page)
return render_to_response('content/restore_version.html', {
'form': form,
'page': page,
'version': version,
'project': page.project,
}, context_instance=RequestContext(request))
示例8: delete_page
def delete_page(request, slug, page_slug):
page = get_object_or_404(Page, project__slug=slug, slug=page_slug)
if page.deleted or not page.editable or not page.listed:
return HttpResponseForbidden(_("You can't edit this page"))
if not page.project.is_organizing(request.user) and not page.collaborative:
return HttpResponseForbidden(_("You can't edit this page"))
if request.method == 'POST':
old_version = PageVersion(title=page.title, content=page.content,
author=page.author, date=page.last_update, page=page)
old_version.save()
page.author = request.user.get_profile()
page.last_update = datetime.datetime.now()
page.deleted = True
page.save()
messages.success(request, _('%s deleted!') % page.title)
return HttpResponseRedirect(reverse('page_history',
kwargs={'slug':page.project.slug, 'page_slug':page.slug}))
else:
return render_to_response('content/confirm_delete_page.html', {
'page': page,
'project': page.project,
}, context_instance=RequestContext(request))
示例9: edit_page
def edit_page(request, slug, page_slug):
page = get_object_or_404(Page, project__slug=slug, slug=page_slug)
if not page.editable:
return HttpResponseForbidden()
user = request.user.get_profile()
if request.user.is_superuser or user == page.project.created_by:
form_cls = OwnersPageForm if page.listed else OwnersNotListedPageForm
elif page.collaborative:
form_cls = PageForm if page.listed else NotListedPageForm
else:
# Restrict permissions for non-collaborative pages.
return HttpResponseForbidden()
if request.method == 'POST':
old_version = PageVersion(title=page.title, content=page.content,
author=page.author, date=page.last_update, page=page)
form = form_cls(request.POST, instance=page)
if form.is_valid():
old_version.save()
page = form.save(commit=False)
page.author = user
page.last_update = datetime.datetime.now()
page.save()
messages.success(request, _('%s updated!') % page.title)
return HttpResponseRedirect(reverse('page_show', kwargs={
'slug': slug,
'page_slug': page_slug,
}))
else:
messages.error(request,
_('There was a problem saving %s.' % page.title))
else:
form = form_cls(instance=page)
return render_to_response('content/edit_page.html', {
'form': form,
'page': page,
'project': page.project,
}, context_instance=RequestContext(request))
示例10: edit_pages
def edit_pages(request, slug):
project = get_object_or_404(Project, slug=slug)
pages = project.pages.filter(deleted=False, listed=True).order_by("index")
if project.is_organizing(request.user):
form_cls = OwnersPageForm
else:
form_cls = PageForm
pages = pages.filter(collaborative=True)
PageFormSet = modelformset_factory(Page, extra=0, fields=form_cls.Meta.fields, can_order=True, can_delete=True)
preview = "show_preview" in request.POST
edit_mode = "edit_mode" in request.POST
add_page = "add_page" in request.POST
save_action = not preview and not edit_mode and not add_page
final_save = "final_save" in request.POST
if request.method == "POST":
post_data = request.POST
try:
total_forms_count = int(post_data["form-TOTAL_FORMS"])
except ValueError, KeyError:
total_forms_count = 0
if add_page:
total_forms_count += 1
post_data = post_data.copy()
post_data["form-TOTAL_FORMS"] = total_forms_count
formset = PageFormSet(post_data, queryset=pages)
forms = formset.forms
if formset.is_valid():
forms = formset.ordered_forms
if save_action:
profile = request.user.get_profile()
current_order = list(pages.values_list("index", flat=True))
new_forms_count = total_forms_count - len(current_order)
if new_forms_count > 0:
try:
first_available_index = project.pages.order_by("-index")[0].index + 1
except IndexError:
first_available_index = 1
current_order.extend(xrange(first_available_index, first_available_index + new_forms_count + 1))
for form in forms:
instance = form.save(commit=False)
if save_action:
instance.author = profile
# FIXME: Starting with Django 1.4 it is possible to
# specify initial values on model formsets so we could include
# the minor_update and collaborative form fields in the future.
if instance.id:
old_page = Page.objects.get(id=instance.id)
old_version = PageVersion(
title=old_page.title,
content=old_page.content,
author=old_page.author,
date=old_page.last_update,
page=instance,
)
old_version.save()
instance.minor_update = True
instance.last_update = datetime.datetime.now()
else:
instance.project = project
if project.category != Project.STUDY_GROUP:
instance.collaborative = False
if form.cleaned_data["ORDER"]:
instance.index = current_order[form.cleaned_data["ORDER"] - 1]
instance.save()
for form in formset.deleted_forms:
instance = form.instance
instance.deleted = True
if save_action and instance.id:
old_page = Page.objects.get(id=instance.id)
old_version = PageVersion(
title=old_page.title,
content=old_page.content,
author=old_page.author,
date=old_page.last_update,
page=instance,
)
old_version.save()
old_page.deleted = True
old_page.author = profile
old_page.last_update = datetime.datetime.now()
old_page.save()
if final_save:
return http.HttpResponseRedirect(project.get_absolute_url())
elif save_action:
return http.HttpResponseRedirect(reverse("edit_pages", kwargs=dict(slug=project.slug)))
else:
if add_page:
messages.info(request, _("Please fill out the new task."))
else:
messages.error(request, _("Please correct errors below."))
preview = False