def create_booklet(request): if request.method == 'POST': song_list = request.POST.getlist("songs[]") front_page_text = request.POST.get("front_page_text") front_page_image = request.POST.get("front_page_image_url") songs = Song.objects.filter(id__in=song_list) user = request.user title = request.POST["title"] book = bookletpy.update_or_create_booklet(songs, user, title, song_list, front_page_text, front_page_image) bookletpy.convert_booklet_to_pdf(book) return HttpResponse(reverse('booklet', kwargs={"id":book.id})) return render(request, "booklets/create_booklet.html")
def get_booklet_pdf(request, id): instance = get_object_or_404(Booklet, pk=id) f = None try: f = open(instance.pdf_file.file.name, 'r') except IOError: #recreate file bookletpy.convert_booklet_to_pdf(instance) f = open(instance.pdf_file.file.name, 'r') myfile = File(f) response = StreamingHttpResponse(myfile, content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename={}'.format(instance) response['X-Sendfile'] = '{}'.format(myfile) return response