def wiki_page_edit(request, slug, template="mezawiki/wiki_page_edit.html"): """ Displays the form for editing a page. """ try: #wiki_pages = WikiPage.objects.published(for_user=request.user) wiki_page = WikiPage.objects.get(slug=slug) wiki_page.is_initial = False initial = {} except WikiPage.DoesNotExist: wiki_page = WikiPage(slug=slug) wiki_page.is_initial = True initial = {'status': 1} if not wiki_page.can_edit_wikipage(request.user): return HttpResponseForbidden( _("You don't have permission to edit this wiki page.")) if request.method == 'POST': form = WikiPageForm(request.POST, instance=wiki_page) if form.is_valid(): page = form.save(commit=False) if wiki_page.is_initial: try: page.user = request.user except: page.user_id = -1 page.title = deurlize_title(slug) page.save() if 'content' in form.changed_data: revision = WikiPageRevision() revision.content = page.content revision.description = form.cleaned_data["summary"] revision.page = page try: revision.user = request.user except: # anonymous revision.user_id = -1 revision.save() return HttpResponseRedirect( reverse('wiki_page_detail', args=[slug])) else: form = WikiPageForm(initial=initial, instance=wiki_page) context = { 'wiki_page': wiki_page, 'form': form, 'title': deurlize_title(slug) } return render(request, template, context)
def wiki_page_edit(request, slug, template="mezawiki/wiki_page_edit.html"): """ Displays the form for editing a page. """ try: #wiki_pages = WikiPage.objects.published(for_user=request.user) wiki_page = WikiPage.objects.get(slug=slug) wiki_page.is_initial = False initial = {} except WikiPage.DoesNotExist: wiki_page = WikiPage(slug=slug) wiki_page.is_initial = True initial = {'status': 1} if not wiki_page.can_edit_wikipage(request.user): return HttpResponseForbidden( _("You don't have permission to edit this wiki page.")) if request.method == 'POST': form = WikiPageForm(request.POST, instance=wiki_page) if form.is_valid(): page = form.save(commit=False) if wiki_page.is_initial: try: page.user = request.user except: page.user_id = -1 page.title = deurlize_title(slug) page.save() if 'content' in form.changed_data: revision = WikiPageRevision() revision.content = page.content revision.description = form.cleaned_data["summary"] revision.page = page try: revision.user = request.user except: # anonymous revision.user_id = -1 revision.save() return HttpResponseRedirect( reverse('wiki_page_detail', args=[slug])) else: form = WikiPageForm(initial=initial, instance=wiki_page) context = {'wiki_page': wiki_page, 'form': form, 'title': deurlize_title(slug)} return render(request, template, context)
def post(self, request, slug, template="mezawiki/wiki_page_edit.html"): try: #wiki_pages = WikiPage.objects.published(for_user=request.user) wiki_page = WikiPage.objects.get(slug=slug) wiki_page.is_initial = False initial = {} except WikiPage.DoesNotExist: wiki_page = WikiPage(slug=slug) wiki_page.is_initial = True initial = {'status': 1} form = WikiPageForm(request.POST, instance=wiki_page) if form.is_valid(): page = form.save(commit=False) if wiki_page.is_initial: try: page.user = request.user except: page.user_id = -1 page.title = deurlize_title(slug) page.save() if 'content' in form.changed_data: revision = WikiPageRevision() revision.content = page.content revision.description = form.cleaned_data["summary"] revision.page = page try: revision.user = request.user except: # anonymous revision.user_id = -1 revision.save() return HttpResponseRedirect( reverse('wiki_page_detail', args=[slug])) else: form = WikiPageForm(initial=initial, instance=wiki_page) context = { 'wiki_page': wiki_page, 'form': form, 'title': deurlize_title(slug) } return render(request, template, context)
def wiki_page_new(request, template="mezawiki/wiki_page_new.html"): """ Displays the form for creating a page. """ if not can_add_wikipage(request.user): return HttpResponseForbidden( _("You don't have permission to create wiki page.")) if request.method == 'POST': form = WikiPageForm(request.POST) if form.is_valid(): page = form.save(commit=False) try: page.user = request.user except: # anonymous page.user_id = -1 page.slug = urlize_title(form.cleaned_data["title"]) # TODO Check slug, it is not a unique field page.save() revision = WikiPageRevision() revision.content = page.content revision.description = form.cleaned_data["summary"] revision.page = page try: revision.user = request.user except: # anonymous revision.user_id = -1 revision.save() return HttpResponseRedirect( reverse('wiki_page_detail', args=[page.slug])) else: form = WikiPageForm(initial={'status': 1}) context = {'form': form} return render(request, template, context)
def wiki_page_new(request, template="mezawiki/wiki_page_new.html"): """ Displays the form for creating a page. """ if not can_add_wikipage(request.user): return HttpResponseForbidden( _("You don't have permission to create wiki page.")) if request.method == 'POST': form = WikiPageForm(request.POST) if form.is_valid(): page = form.save(commit=False) try: page.user = request.user except: # anonymous page.user_id = -1 page.slug = urlize_title(form.cleaned_data["title"]) # TODO Check slug, it is not a unique field page.save() revision = WikiPageRevision() revision.content = page.content revision.description = form.cleaned_data["summary"] revision.page = page try: revision.user = request.user except: # anonymous revision.user_id = -1 revision.save() return HttpResponseRedirect( reverse('wiki_page_detail', args=[page.slug])) else: form = WikiPageForm(initial={'status': 1}) context = {'form': form} return render(request, template, context)