def create_page(request, page_title): if request.method == "POST": form = PageRevisionForm(request.POST) if form.is_valid(): page, created = Page.objects.get_or_create(title=page_title) form.save(page) messages.success(request, action_messages.get("page_created")) return HttpResponseRedirect(reverse_lazy("view_page", args=[page_title])) else: form = PageRevisionForm() return render_to_response("wiki/create_or_edit_page.jinja", locals())
def revert_page_to_revision(request, page_title, revision_id): page = get_object_or_404(Page, title=page_title) revision = get_object_or_404(Revision, page=page, id=revision_id) if request.method == "POST": form = RevertRevisionForm(request.POST) if form.is_valid(): form.save(page, revision) messages.success(request, action_messages.get("page_reverted") % revision.datetime) return HttpResponseRedirect(reverse_lazy("view_page", args=[page_title])) else: form = RevertRevisionForm() return render_to_response("wiki/revert_page_to_revision.jinja", locals())
def edit_page(request, page_title): page = get_object_or_404(Page, title=page_title) current_revision = page.current form = PageRevisionForm(initial=current_revision.to_dict()) if request.method == "POST": """ do not allow any other changes """ form = PageRevisionForm(request.POST, initial=current_revision.to_dict()) if form.is_valid(): form.save(page) messages.success(request, action_messages.get("page_updated")) return HttpResponseRedirect(reverse_lazy("view_page", args=[page_title])) return render_to_response("wiki/create_or_edit_page.jinja", locals())