Example #1
0
def as_text_only_fileset(request, document_id):
    form = TextOnlyFilesetForm(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
    outputDir = tempfile.mkdtemp(prefix="daisyproducer-")

    DaisyPipeline.dtbook2text_only_fileset(inputFile, outputDir, **form.cleaned_data)

    ignore, zipFileName = tempfile.mkstemp(suffix='.zip', prefix=document_id)
    zipDirectory(outputDir, zipFileName, document.title)
    shutil.rmtree(outputDir)
    
    return render_to_mimetype_response('application/zip', document.title.encode('utf-8'), zipFileName)
Example #2
0
def preview_text_only_fileset(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = TextOnlyFilesetForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputDir = tempfile.mkdtemp(prefix="daisyproducer-")

            DaisyPipeline.dtbook2text_only_fileset(inputFile, outputDir, **form.cleaned_data)

            ignore, zipFileName = tempfile.mkstemp(suffix='.zip', prefix=document_id)
            zipDirectory(outputDir, zipFileName, document.title)
            shutil.rmtree(outputDir)
    
            return render_to_mimetype_response('application/zip', 
                                               document.title.encode('utf-8'), zipFileName)
    else:
        form = TextOnlyFilesetForm()

    return render_to_response('documents/todo_text_only_fileset.html', locals(),
                              context_instance=RequestContext(request))