+
+
+# info views for API
+
+def book_info(request, id, lang='pl'):
+ book = get_object_or_404(models.Book, id=id)
+ # set language by hand
+ translation.activate(lang)
+ return render_to_response('catalogue/book_info.html', locals(),
+ context_instance=RequestContext(request))
+
+
+def tag_info(request, id):
+ tag = get_object_or_404(models.Tag, id=id)
+ return HttpResponse(tag.description)
+
+
+def download_zip(request, format, slug):
+ url = None
+ if format in ('pdf', 'epub', 'mobi'):
+ url = models.Book.zip_format(format)
+ elif format == 'audiobook' and slug is not None:
+ book = models.Book.objects.get(slug=slug)
+ url = book.zip_audiobooks()
+ else:
+ raise Http404('No format specified for zip package')
+ return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))
+
+
+def download_custom_pdf(request, slug):
+ book = models.Book.objects.get(slug=slug)
+ if request.method == 'GET':
+ form = forms.CustomPDFForm(request.GET)
+ if form.is_valid():
+ cust = form.customizations
+ pdf_file = models.get_customized_pdf_path(book, cust)
+
+ if not path.exists(pdf_file):
+ result = async_build_pdf.delay(book.id, cust, pdf_file)
+ result.wait()
+ return AttachmentHttpResponse(file_name=("%s.pdf" % book.slug), file_path=pdf_file, mimetype="application/pdf")
+ else:
+ raise Http404(_('Incorrect customization options for PDF'))
+ else:
+ raise Http404(_('Bad method'))