+ if request.user.is_authenticated():
+ author = request.user
+ else:
+ author = None
+ text = form.cleaned_data['text']
+ # parent_revision = form.cleaned_data['parent_revision']
+ # if parent_revision is not None:
+ # parent = doc.at_revision(parent_revision)
+ # else:
+ # parent = None
+ stage = form.cleaned_data['stage']
+ # tags = [stage] if stage else []
+ # publishable = (form.cleaned_data['publishable'] and
+ # request.user.has_perm('catalogue.can_pubmark'))
+ try:
+ doc.commit(
+ author=author,
+ text=text,
+ description=form.cleaned_data['comment'],
+ author_name=form.cleaned_data['author_name'],
+ author_email=form.cleaned_data['author_email'],
+ )
+ doc.set_stage(stage)
+ except:
+ from traceback import print_exc
+ print_exc()
+ raise
+ return JSONResponse({
+ 'text': None, # doc.materialize() if parent_revision != revision else None,
+ '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)
+ else:
+ revision = request.GET.get("revision", None)
+
+ try:
+ revision = int(revision)
+ except (ValueError, TypeError):
+ revision = doc.revision()
+
+ if revision is not None:
+ text = doc.at_revision(revision).materialize()
+ else:
+ text = ''
+
+ return JSONResponse({
+ 'text': text,
+ 'meta': {},
+ 'revision': revision,
+ })
+
+
+@never_cache
+@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