+ output_file = NamedTemporaryFile(prefix='librarian', suffix='.mobi', delete=False)
+ output_file.close()
+ subprocess.check_call(
+ ['ebook-convert', epub_file.get_filename(), output_file.name, '--no-inline-toc'])
+
+ from catalogue.ebook_utils import serve_file
+ return serve_file(output_file.name, '%d.mobi' % doc.pk, 'application/epub+zip')
+
+
+# @never_cache
+# def revision(request, slug, chunk=None):
+# try:
+# doc = Chunk.get(slug, chunk)
+# except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist):
+# raise Http404
+# if not doc.book.accessible(request):
+# return HttpResponseForbidden("Not authorized.")
+# return http.HttpResponse(str(doc.revision()))
+
+
+@login_required
+def book_schedule(request, pk):
+ book = get_object_or_404(Document, pk=pk, deleted=False)
+ if request.method == 'POST':
+ Plan.objects.filter(document=book).delete()
+ for i, s in enumerate(STAGES):
+ user_id = request.POST.get('s%d-user' % i)
+ deadline = request.POST.get('s%d-deadline' % i) or None
+ Plan.objects.create(document=book, stage=s, user_id=user_id, deadline=deadline)
+
+ book.set_stage(request.POST.get('stage', ''))
+ return redirect('catalogue_user')
+
+ current = {}
+ for p in Plan.objects.filter(document=book):
+ current[p.stage] = (getattr(p.user, 'pk', None), (p.deadline.isoformat() if p.deadline else None))
+
+ schedule = [(i, s, current.get(s, ())) for (i, s) in enumerate(STAGES)]
+
+ if book.owner_organization:
+ people = [m.user for m in book.owner_organization.membership_set.exclude(status='pending')]
+ else:
+ people = [book.owner_user]
+ return render(request, 'catalogue/book_schedule.html', {
+ 'book': book,
+ 'schedule': schedule,
+ 'people': people,