- return HttpResponse(json.dumps({'text': document.plain_text, 'meta': document.meta(), 'revision': document.revision()}))
-
+ revision = request.GET.get("revision", None)
+
+ try:
+ try:
+ revision = revision and int(revision)
+ logger.info("Fetching %s", revision)
+ document = storage.get(name, revision)
+ except ValueError:
+ # treat as a tag
+ logger.info("Fetching tag %s", revision)
+ document = storage.get_by_tag(name, revision)
+ except DocumentNotFound:
+ raise http.Http404
+
+ return JSONResponse({
+ 'text': document.plain_text,
+ 'meta': document.meta(),
+ 'revision': document.revision,
+ })
+
+
+@never_cache
+@normalized_name
+@require_POST
+def revert(request, name):
+ storage = getstorage()
+ revision = request.POST['target_revision']
+
+ try:
+ document = storage.revert(name, revision)