Beispiel #1
0
def preview_epub(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = EPUBForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = "/tmp/%s.epub" % document_id
            defaults = {
                "dctitle" : document.title, 
                "dcidentifier" : document.identifier, 
                "dclanguage" : document.language, 
                "dccreator" : document.author, 
                "dcpublisher" : document.publisher, 
                "dcdate" : document.date}
            defaults.update(form.cleaned_data)
            DaisyPipeline.dtbook2epub(inputFile, outputFile,
                                      images=document.image_set.all(), **defaults)
            return render_to_mimetype_response('application/epub+zip', 
                                               document.title.encode('utf-8'), outputFile)
    else:
        form = EPUBForm()

    return render_to_response('documents/todo_epub.html', locals(),
                              context_instance=RequestContext(request))
Beispiel #2
0
def as_epub(request, document_id):
    form = EPUBForm(request.POST)

    if not form.is_valid():
        return HttpResponseRedirect(reverse('browse_detail', args=[document_id]))

    document = Document.objects.get(pk=document_id)
    inputFile = document.latest_version().content.path
    outputFile = "/tmp/%s.epub" % document_id
    defaults = {
        "dctitle" : document.title, 
        "dcidentifier" : document.identifier, 
        "dclanguage" : document.language, 
        "dccreator" : document.author, 
        "dcpublisher" : document.publisher, 
        "dcdate" : document.date}
    defaults.update(form.cleaned_data)
    DaisyPipeline.dtbook2epub(inputFile, outputFile, **defaults)

    return render_to_mimetype_response('application/epub+zip', document.title.encode('utf-8'), outputFile)