- raise Http404
-
-def document_diff(request, name, revA, revB):
- differ = difflib.HtmlDiff(wrapcolumn=60)
-
- docA = storage.get(name, int(revA))
- docB = storage.get(name, int(revB))
-
- return HttpResponse(differ.make_table(
- docA.plain_text.splitlines(),
- docB.plain_text.splitlines() ) )
-
-
-def document_history(reuqest, name):
- return HttpResponse( json.dumps(storage.history(name), cls=DateTimeEncoder), mimetype='application/json')
+ return JSONResponse(images)
+ except (IndexError, OSError):
+ logger.exception("Unable to fetch gallery")
+ raise http.Http404
+
+
+@never_cache
+def diff(request, doc_id):
+ revA = int(request.GET.get('from', 0))
+ revB = int(request.GET.get('to', 0))
+
+ if revA > revB:
+ revA, revB = revB, revA
+
+ if revB == 0:
+ revB = None
+
+ # TODO: check if revisions in line.
+
+ doc = get_object_or_404(Document, pk=doc_id, deleted=False)
+
+ # allow diff from the beginning
+ if revA:
+ docA = Revision.objects.get(pk=revA).materialize()
+ else:
+ docA = ""
+ docB = Revision.objects.get(pk=revB).materialize()
+
+ return http.HttpResponse(nice_diff.html_diff_table(docA.splitlines(),
+ docB.splitlines(), context=3))
+
+
+@never_cache
+def revision(request, chunk_id):
+ doc = get_object_or_404(Chunk, pk=chunk_id)
+ if not doc.book.accessible(request):
+ return HttpResponseForbidden("Not authorized.")
+ return http.HttpResponse(str(doc.revision()))
+
+
+@never_cache
+def history(request, doc_id):
+ # TODO: pagination
+ doc = get_object_or_404(Document, pk=doc_id, deleted=False)
+
+ return JSONResponse(get_history(doc))