+ try:
+ revision = int(revision)
+ except (ValueError, TypeError):
+ revision = None
+
+ return JSONResponse({
+ 'text': doc.at_revision(revision).materialize(),
+ 'meta': {},
+ 'revision': revision if revision else doc.revision(),
+ })
+
+
+@never_cache
+def book_xml(request, slug):
+ xml = get_object_or_404(Book, slug=slug).materialize()
+
+ response = http.HttpResponse(xml, content_type='application/xml', mimetype='application/wl+xml')
+ response['Content-Disposition'] = 'attachment; filename=%s.xml' % slug
+ return response
+
+
+@never_cache
+def book_txt(request, slug):
+ xml = get_object_or_404(Book, slug=slug).materialize()
+ output = StringIO()
+ # errors?
+ librarian.text.transform(StringIO(xml), output)
+ text = output.getvalue()
+ response = http.HttpResponse(text, content_type='text/plain', mimetype='text/plain')
+ response['Content-Disposition'] = 'attachment; filename=%s.txt' % slug
+ return response
+
+
+@never_cache
+def book_html(request, slug):
+ xml = get_object_or_404(Book, slug=slug).materialize()
+ output = StringIO()
+ # errors?
+ librarian.html.transform(StringIO(xml), output, parse_dublincore=False,
+ flags=['full-page'])
+ html = output.getvalue()
+ response = http.HttpResponse(html, content_type='text/html', mimetype='text/html')
+ return response
+
+
+@never_cache
+@require_POST
+def revert(request, slug, chunk=None):
+ form = DocumentTextRevertForm(request.POST, prefix="textrevert")
+ if form.is_valid():
+ try:
+ doc = Chunk.get(slug, chunk)
+ except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist):
+ raise Http404
+
+ revision = form.cleaned_data['revision']
+
+ comment = form.cleaned_data['comment']
+ comment += "\n#revert to %s" % revision
+
+ if request.user.is_authenticated():
+ author = request.user
+ else:
+ author = None
+
+ before = doc.revision()
+ logger.info("Reverting %s to %s", slug, revision)
+ doc.at_revision(revision).revert(author=author, description=comment)
+
+ return JSONResponse({
+ 'text': doc.materialize() if before != doc.revision() else None,
+ 'meta': {},
+ 'revision': doc.revision(),
+ })
+ else:
+ return JSONFormInvalid(form)
+
+
+@never_cache
+def gallery(request, directory):
+ try:
+ base_url = ''.join((
+ smart_unicode(settings.MEDIA_URL),