X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/1617abdf1a5ec504c28f52daf2a2b1728a5b28f6..87353f5cb22922879ef64b9e788a50a549404132:/apps/wiki/views.py?ds=inline diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 33d6610b..9a156a4c 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -1,5 +1,6 @@ from django.views.generic.simple import direct_to_template -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse +from django.utils import simplejson as json from wiki.models import storage, Document, DocumentNotFound from wiki.forms import DocumentForm @@ -16,14 +17,15 @@ def document_detail(request, name, template_name='wiki/document_details.html'): document = storage.get(name) except DocumentNotFound: document = Document(storage, name=name, text='') - + + if request.method == 'POST': form = DocumentForm(request.POST, instance=document) if form.is_valid(): - form.save() - return HttpResponse('OK') + document = form.save() + return HttpResponse(json.dumps({'text': document.plain_text(), 'meta': document.meta(), 'revision': document.revision()})) else: - print form.errors + return HttpResponse(json.dumps({'errors': form.errors})) else: form = DocumentForm(instance=document)