+@never_cache
+def document_text(request, name):
+ storage = getstorage()
+ document = storage.get_or_404(name)
+
+ if request.method == 'POST':
+ 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()
+ })
+ else:
+ return JSONFormInvalid(form)
+ else:
+ return JSONResponse({
+ 'text': document.plain_text,
+ 'meta': document.meta(),
+ 'revision': document.revision()
+ })
+
+