+@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)
+ if not doc.can_edit(request.user):
+ return HttpResponseForbidden("Not authorized.")
+ 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(),
+ description=comment,
+ # author_name=form.cleaned_data['author_name'], #?
+ # author_email=form.cleaned_data['author_email'], #?
+ )
+
+ return JSONResponse({
+ 'document': doc.materialize(),
+ 'version': len(get_history(doc)),
+ 'stage': doc.stage,
+ 'stage_name': doc.stage_name(),
+ 'assignment': doc.assigned_to.username if doc.assigned_to else None,
+ })
+ else:
+ return JSONFormInvalid(form)
+
+
+@never_cache
+def gallery(request, directory):
+ if not request.user.is_authenticated():
+ return HttpResponseForbidden("Not authorized.")
+