OpenOffice Utils via appy.pod

Note

Nuovo

Questo modulo rimpiazza OpenOffice utils

Il modulo utilizza la libreria appy.pod per generare documenti a partire da un template in formato .odt.

Esempio d’uso:

from django.http import HttpResponse

from jmb.core.utils.appypod import AppyPodTemplate

def example_view_pdf(request):
    context = dict(first_name="<name>", last_name="<last_name>")
    appy_pod_template = AppyPodTemplate('admin/fax/cover.odt', context)
    return HttpResponse(template.render(), mimetype="application/pdf")

def example_view_odt(request):
    context = dict(first_name="<name>", last_name="<last_name>")
    appy_pod_template = AppyPodTemplate('admin/fax.cover.odt', context)
    return HttpResponse(template.render(file_type="odt"), 
                        mimetype="application/vnd.oasis.opendocument.text")

conversion

A conversion utility is provided that uses OpenOffice/LibreOffice to convert among possible formats. Tipical usage allows to convert bunch of documents toghether, passing both patterns of directory to transverse and patterns:

from jmb.core.utils import appypod

appypod.convert(file_names='/tmp/report.odt', result_type='doc')
appypod.convert(tree='/home/data/fax', file_names="*doc")

API

class jmb.core.utils.appypod.AppyPodTemplate(template=None, context=None)[source]

Interface to get handle templates in .odt, .ods

Object init function.

Parameters:
  • template – (string) template file to render. Std django search is performed
  • context – context to be used on template rendering
render(file_type='pdf')[source]

Instance render function.

Parameters:file_type – output file extension
Returns:generated file stream if created, else None
save_as(output_path)[source]

Save the template into file

Parameters:output_path – the output path
Returns:the open handler of the generated file
set_template(template)[source]

Set template

Parameters:template – (string) template file to render. Std django search is applied
jmb.core.utils.appypod.convert(name_pattern, result_type='pdf', tree=None)[source]

Call LibreOffice in server mode to convert or update the result.

Parameters:
  • name_pattern – the file name to be converted. A list, a set, a tuple of filenames or a glob pattern is accepted. If tree is defined name_pattern is interpreted as a pattern.
  • file_type – the resul_type desired (default: pdf)
  • tree – if tree is defined the whole directory is traversed for pattern and name_pattern is interpreted as a pattern

This Page