- form = DocumentForm(request.POST, instance = document)
- if form.is_valid():
- document = form.save(document_author = request.user.username)
- return HttpResponse(json.dumps({'text': document.plain_text, 'meta': document.meta(), 'revision': document.revision()}))
+ form = DocumentTextSaveForm(request.POST)
+
+ if form.is_valid():
+ revision = form.cleaned_data['parent_revision']
+ document.text = form.cleaned_data['text']
+
+ storage.put(document,
+ author = form.cleaned_data['author'] or request.user.username,
+ comment = form.cleaned_data['comment'],
+ parent = revision
+ )
+
+ return JSONResponse({
+ 'text': document.plain_text if revision != document.revision() else None,
+ 'meta': document.meta(),
+ 'revision': document.revision()
+ })