Commit 95bc6187 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '25-docx' into 'master'

25 docx

* List can be extract as an `odt` file. Extraction in `csv` is removed.
* The `html` file is converted as an `odt` file by `LibreOffice`. The style is preserved: list italic, italic, bold, underlying, *etc*. However, the equation are not translate.
* File following the OpenDocument specification can be open and modify by the modern version of Microsoft word.
* The use of `LibreOffice` should help in the long term maintenance.
* Close #25.

See merge request !52
parents 23f47a5a 0162677c
......@@ -2,7 +2,7 @@
""" list_selector (virtaul table)
"""
FORMATS = ['bib', 'csv', 'html', 'pdf', 'tex']
FORMATS = ['bib', 'html', 'odt', 'pdf', 'tex']
#-------------------------------------------------------------------------------
#
......
{{include 'lists/index.html'}}
{{
import base64
import cStringIO
import os
from subprocess import call
from tempfile import TemporaryFile
from uuid import uuid4
#
# go to the build directory
#
cwd = os.getcwd()
wd = os.path.join(request.folder, 'tmp_build')
if not os.path.exists(wd):
os.chdir(request.folder)
os.mkdir('tmp_build')
os.chdir('tmp_build')
else:
os.chdir(wd)
pass
#
# create the HTML file
#
shtml = '<head></head><body>%s</body>' % response.body.getvalue()
froot = str(uuid4())
fhtml = '%s.html' % froot
fi = open(fhtml, 'wb')
fi.write(shtml)
fi.close()
#
# convert the HTML in ODT file
#
cmd = ["libreoffice", "--headless", "--convert-to", "odt", fhtml]
call(cmd, stdout=TemporaryFile())
fodt = '%s.odt' % froot
fi = open(fodt, 'rb')
sodt = fi.read()
fi.close()
s64 = base64.b64encode(sodt)
#
# clean
#
for ext in ('html', 'odt'):
f = '%s.%s' % (froot, ext)
if os.path.exists(f):
os.remove(f)
pass
pass
os.chdir(cwd)
#
# build the response
#
response.body = cStringIO.StringIO()
response.headers['Content-Type']='application/vnd.oasis.opendocument.text'
response.headers['Content-Disposition'] = 'attachment;filename="list.odt"'
response.write(s64, escape=False)
}}
\ No newline at end of file
......@@ -23,11 +23,11 @@
# go to the private directory and create a latex file
#
cwd = os.getcwd()
wd = os.path.join(request.folder, 'latex')
wd = os.path.join(request.folder, 'tmp_build')
if not os.path.exists(wd):
os.chdir(request.folder)
os.mkdir('latex')
os.chdir('latex')
os.mkdir('tmp_build')
os.chdir('tmp_build')
else:
os.chdir(wd)
pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment