def wiki_page_edit(request, page_path, _page_obj=None): page = _page_obj or WikiPage.get_object_by_path(page_path) preview_action = request.POST and 'preview' in request.POST if request.POST: form = WikiPageForm(data=request.POST, initial={'author':request.user}, instance=page) if form.is_valid(): page = form.save(commit=False) if not preview_action: pages = WikiPage.make_path(page_path, kwargs={'author':request.user}) if pages: page.parent_page = pages[-1] page.title = WikiPage.get_title_from_path(page_path) print page_path print page.title page.author = request.user page.save() return redirect('wiki_page', page_path=page_path) else: form = WikiPageForm(initial={'author':request.user}, instance=page) context = {} context['page'] = page context['page_path'] = page_path context['form'] = form context['preview_action'] = preview_action return context
def create_page(request): """ Creates a new page. Templates: ``create_page.html`` Context: form WikiPageForm object """ if request.method == 'POST': form = WikiPageForm(request.POST) if form.is_valid(): page = form.save(commit=False) page.creator = request.user page.save() return redirect(page) else: form = WikiPageForm() return render_to_response('vz_wiki/create_page.html', {'form': form}, context_instance=RequestContext(request))
def wiki_edit(request, namespace, name): ns = get_object_or_404(Namespace, owner=request.user, name=namespace) if not ns.can_update(request.user): return HttpResponseRedirect(reverse('peach.mobile_views.namespace', kwargs={'namespace':namespace})) page = WikiPage.objects.get_or_create(namespace=ns, name=name)[0] if request.method == 'POST': page_form = WikiPageForm(request.POST, instance=page) if page_form.is_valid(): page = page_form.save() if request.GET.get('next', None): return HttpResponseRedirect(request.GET.get('next')) return HttpResponseRedirect(page.get_mobile_url()) else: page_form = WikiPageForm(instance=page) return render_to_response('peach/mobile/wiki_edit.html', { 'page':page, 'page_form':page_form }, context_instance=RequestContext(request))