Example #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))
Example #2
0
def preview_sbsform_new(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = SBSFormForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = Pipeline2.dtbook2sbsform(
                inputFile,
                document_identifier=document.identifier,
                use_local_dictionary=document.has_local_words(),
                **form.cleaned_data)

            if isinstance(outputFile, tuple):
                # if filename is a tuple we're actually looking at a list of error messages
                errorMessages = outputFile
                return render_to_response('documents/todo_sbsform.html', locals(),
                                          context_instance=RequestContext(request))

            contraction = form.cleaned_data['contraction']
            contraction_to_mimetype_mapping = {0 : 'text/x-sbsform-g0',
                                               1 : 'text/x-sbsform-g1',
                                               2 : 'text/x-sbsform-g2'}
            mimetype = contraction_to_mimetype_mapping.get(contraction, 'text/x-sbsform-g2')
            return render_to_mimetype_response(mimetype, document.title.encode('utf-8'), outputFile)
    else:
        form = SBSFormForm()

    return render_to_response('documents/todo_sbsform.html', locals(),
                              context_instance=RequestContext(request))
Example #3
0
def preview_library_pdf(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    inputFile = document.latest_version().content.path
    outputFile = "/tmp/%s.pdf" % document_id
    StandardLargePrint.dtbook2pdf(inputFile, outputFile)
    filename = document.title + u" 17pt"
    return render_to_mimetype_response('application/pdf', filename.encode('utf-8'), outputFile)
Example #4
0
def export_words(request):
    if request.method == 'GET':
        tmp = tempfile.NamedTemporaryFile(prefix="daisyproducer-", suffix=".csv", delete=False)
        tmp.close() # we are only interested in a unique filename
        f = codecs.open(tmp.name, "w", "utf-8")
        exportWords(f)
        f.close()
        return render_to_mimetype_response('text/csv', 'Global dictionary dump', tmp.name)
Example #5
0
def preview_xhtml(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    inputFile = document.latest_version().content.path
    outputFile = "/tmp/%s.xhtml" % document_id
    params = {}
    DaisyPipeline.dtbook2xhtml(inputFile, outputFile, **params)

    return render_to_mimetype_response('text/html', 
                                       document.title.encode('utf-8'), outputFile)
Example #6
0
def as_xhtml(request, document_id):
    form = XHTMLForm(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.xhtml" % document_id
    DaisyPipeline.dtbook2xhtml(inputFile, outputFile, **form.cleaned_data)

    return render_to_mimetype_response('text/html', document.title.encode('utf-8'), outputFile)
Example #7
0
def as_pdf(request, document_id):
    form = LargePrintProfileForm(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.pdf" % document_id
    DaisyPipeline.dtbook2pdf(inputFile, outputFile, **form.cleaned_data)

    return render_to_mimetype_response('application/pdf', document.title.encode('utf-8'), outputFile)
Example #8
0
def as_brl(request, document_id):
    form = BrailleProfileForm(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.brl" % document_id
    Liblouis.dtbook2brl(inputFile, outputFile, **form.cleaned_data)

    return render_to_mimetype_response('text/x-brl', document.title.encode('utf-8'), outputFile)
Example #9
0
def preview_rtf(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = RTFForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = "/tmp/%s.rtf" % document_id
            DaisyPipeline.dtbook2rtf(inputFile, outputFile, **form.cleaned_data)
            return render_to_mimetype_response('application/rtf', 
                                               document.title.encode('utf-8'), outputFile)
    else:
        form = RTFForm()

    return render(request, 'documents/todo_rtf.html', locals())
Example #10
0
def as_sbsform(request, document_id):
    form = SBSFormForm(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.sbsform" % document_id
    SBSForm.dtbook2sbsform(inputFile, outputFile, **form.cleaned_data)
    contraction = form.cleaned_data['contraction']
    contraction_to_mimetype_mapping = {0 : 'text/x-sbsform-g0', 
                                       1 : 'text/x-sbsform-g1',
                                       2 : 'text/x-sbsform-g2'}
    mimetype = contraction_to_mimetype_mapping.get(contraction, 'text/x-sbsform-g2')
    return render_to_mimetype_response(mimetype, document.title.encode('utf-8'), outputFile)
Example #11
0
def preview_pdf(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = LargePrintProfileForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = "/tmp/%s.pdf" % document_id
            DaisyPipeline.dtbook2pdf(inputFile, outputFile, **form.cleaned_data)
            return render_to_mimetype_response('application/pdf', 
                                               document.title.encode('utf-8'), outputFile)
    else:
        form = LargePrintProfileForm()

    return render_to_response('documents/todo_pdf.html', locals(),
                              context_instance=RequestContext(request))
Example #12
0
def as_dtb(request, document_id):
    form = DTBForm(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.dtbook2dtb(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 #13
0
def preview_sale_pdf(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = SalePDFForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = "/tmp/%s.pdf" % document_id
            StandardLargePrint.dtbook2pdf(inputFile, outputFile, **form.cleaned_data)
            filename = document.title + u" " + form.cleaned_data['font_size']
            return render_to_mimetype_response('application/pdf', 
                                               filename.encode('utf-8'), outputFile)
    else:
        form = SalePDFForm()

    return render_to_response('documents/todo_sale_pdf.html', locals(),
                              context_instance=RequestContext(request))
Example #14
0
def all_data_as_csv(request):
    """Get all data as a comma separated values file"""
    outputFileName = "/tmp/stats_data.csv"
    outputFile = open(outputFileName, 'wb')
    writer = csv.writer(outputFile)
    writer.writerow(['Date', 'Document', 'Grade', 'Total', 'Unknown'])
    stats = DocumentStatistic.objects
    # Only keep first occurence of document
    stats = stats.raw("""
SELECT id,max(statistics_documentstatistic.unknown)
FROM statistics_documentstatistic
GROUP BY statistics_documentstatistic.document_id
ORDER BY statistics_documentstatistic.date;
""")
    for stat in stats:
        writer.writerow([stat.date, stat.document.identifier, stat.grade, stat.total, stat.unknown])
    outputFile.close()
    return render_to_mimetype_response('text/csv', 'XMLP Statistical Data', outputFileName)
Example #15
0
def as_text_only_dtb(request, document_id):
    form = TextOnlyDTBForm(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_dtb(inputFile, outputDir, **form.cleaned_data)

    zipFile = tempfile.NamedTemporaryFile(suffix='.zip', prefix=document_id, delete=False)
    zipFile.close() # we are only interested in a unique filename
    zipDirectory(outputDir, zipFile.name, document.title)
    shutil.rmtree(outputDir)
    
    return render_to_mimetype_response('application/zip', document.title.encode('utf-8'), zipFile.name)
Example #16
0
def preview_sbsform(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = SBSFormForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputFile = "/tmp/%s.sbsform" % document_id
            SBSForm.dtbook2sbsform(inputFile, outputFile, **form.cleaned_data)
            contraction = form.cleaned_data['contraction']
            contraction_to_mimetype_mapping = {0 : 'text/x-sbsform-g0', 
                                               1 : 'text/x-sbsform-g1',
                                               2 : 'text/x-sbsform-g2'}
            mimetype = contraction_to_mimetype_mapping.get(contraction, 'text/x-sbsform-g2')
            return render_to_mimetype_response(mimetype, document.title.encode('utf-8'), outputFile)
    else:
        form = SBSFormForm()

    return render_to_response('documents/todo_sbsform.html', locals(),
                              context_instance=RequestContext(request))
Example #17
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)
Example #18
0
def preview_dtb(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = DTBForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputDir = tempfile.mkdtemp(prefix="daisyproducer-")
            DaisyPipeline.dtbook2dtb(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 = DTBForm()

    return render_to_response('documents/todo_dtb.html', locals(),
                              context_instance=RequestContext(request))
Example #19
0
def preview_dtb(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = DTBForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            outputDir = tempfile.mkdtemp(prefix="daisyproducer-")
            DaisyPipeline.dtbook2dtb(inputFile, outputDir, **form.cleaned_data)

            zipFile = tempfile.NamedTemporaryFile(suffix='.zip', prefix=document_id, delete=False)
            zipFile.close() # we are only interested in a unique filename
            zipDirectory(outputDir, zipFile.name, document.title)
            shutil.rmtree(outputDir)

            return render_to_mimetype_response('application/zip', 
                                               document.title.encode('utf-8'), zipFile.name)
    else:
        form = DTBForm()

    return render(request, 'documents/todo_dtb.html', locals())
Example #20
0
def preview_text_only_dtb(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

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

            transformationErrors = DaisyPipeline.dtbook2text_only_dtb(
                inputFile, outputDir,
                images=document.image_set.all(), **form.cleaned_data)
            if transformationErrors:
                return render_to_response('documents/todo_text_only_dtb.html', locals(),
                                          context_instance=RequestContext(request))

            zipFile = tempfile.NamedTemporaryFile(suffix='.zip', prefix=document_id, delete=False)
            zipFile.close() # we are only interested in a unique filename
            zipDirectory(outputDir, zipFile.name, ebookNumber)
            shutil.rmtree(outputDir)

            # put a copy of the ebook to a shared folder where it is fetched by another process that
            # puts into the distribution system. This will change, as the distribution system should
            # fetch the ebook directly from the archive. See fhs for a rationale about the dest
            # folder (http://www.pathname.com/fhs/pub/fhs-2.3.html#VARSPOOLAPPLICATIONSPOOLDATA)
            shutil.copy2(zipFile.name, os.path.join('/var/spool/daisyproducer', ebookNumber + '.zip'))
    
            return render_to_mimetype_response('application/zip', 
                                               document.title.encode('utf-8'), zipFile.name)
    else:
        ebook = Product.objects.filter(document=document, type=2)
        if ebook:
            form = TextOnlyDTBForm({'ebookNumber': ebook[0].identifier})
        else:
            form = TextOnlyDTBForm()

    return render_to_response('documents/todo_text_only_dtb.html', locals(),
                              context_instance=RequestContext(request))
Example #21
0
def preview_odt(request, document_id):
    document = get_object_or_404(Document, pk=document_id)

    if request.method == 'POST':
        form = ODTForm(request.POST)
        if form.is_valid():
            inputFile = document.latest_version().content.path
            filename = Pipeline2.dtbook2odt(inputFile,
                                            imageFiles=document.image_set.all(),
                                            **form.cleaned_data)

            if isinstance(filename, tuple):
                # if filename is a tuple we're actually looking at a list of error messages
                errorMessages = filename
                return render(request, 'documents/todo_odt.html', locals())

            return render_to_mimetype_response('application/vnd.oasis.opendocument.text', 
                                               document.title.encode('utf-8'), filename)
    else:
        form = ODTForm()

    return render(request, 'documents/todo_odt.html', locals())
Example #22
0
def words_with_wrong_default_translation(request):
    words = GlobalWord.objects.order_by('untranslated')
    return render_to_mimetype_response(
        'text/csv', 
        'Global words with wrong rule based translation', 
        write_words_with_wrong_default_translation(words))