+@require_POST
+def revert(request, doc_id):
+ form = forms.DocumentTextRevertForm(request.POST, prefix="textrevert")
+ if form.is_valid():
+ doc = get_object_or_404(Document, pk=doc_id, deleted=False)
+ rev = get_object_or_404(Revision, pk=form.cleaned_data['revision'])
+
+ comment = form.cleaned_data['comment']
+ comment += "\n#revert to %s" % rev.pk
+
+ if request.user.is_authenticated():
+ author = request.user
+ else:
+ author = None
+
+ #before = doc.revision
+ logger.info("Reverting %s to %s", doc_id, rev.pk)
+
+ doc.commit(author=author,
+ text=rev.materialize(),
+ parent=False, #?
+ description=comment,
+ #author_name=form.cleaned_data['author_name'], #?
+ #author_email=form.cleaned_data['author_email'], #?
+ )
+
+ return JSONResponse({
+ #'document': None, #doc.materialize() if before != doc.revision else None,
+ #'version': doc.revision(),
+ })
+ else:
+ return JSONFormInvalid(form)
+
+
+@never_cache
+def gallery(request, directory):
+ if not request.user.is_authenticated():
+ return HttpResponseForbidden("Not authorized.")
+