Skip to content

Commit 04041a9

Browse files
committed
Enable filter options support. jptd#1
1 parent c2bd2d2 commit 04041a9

File tree

11 files changed

+56
-30
lines changed

11 files changed

+56
-30
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ target/
6060

6161
# LibreOffice temporary files
6262
~$*.odt
63+
64+
# PyCharm
65+
.idea/
66+
67+
# pyenv
68+
.python-version

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ deploy:
2525
user: inductor
2626
on:
2727
condition: $TOXENV == py34-django19
28-
repo: alexmorozov/templated-docs
28+
repo: kiawin/templated-docs
2929
tags: true

AUTHORS.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Development Lead
1010
Contributors
1111
------------
1212

13-
None yet. Why not be the first?
13+
* Sian Lerk Lau <kiawin@gmail.com>

CONTRIBUTING.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Types of Contributions
1515
Report Bugs
1616
~~~~~~~~~~~
1717

18-
Report bugs at https://github.com/alexmorozov/templated-docs/issues.
18+
Report bugs at https://github.com/kiawin/templated-docs/issues.
1919

2020
If you are reporting a bug, please include:
2121

@@ -45,7 +45,7 @@ articles, and such.
4545
Submit Feedback
4646
~~~~~~~~~~~~~~~
4747

48-
The best way to send feedback is to file an issue at https://github.com/alexmorozov/templated-docs/issues.
48+
The best way to send feedback is to file an issue at https://github.com/kiawin/templated-docs/issues.
4949

5050
If you are proposing a feature:
5151

@@ -101,8 +101,8 @@ Before you submit a pull request, check that it meets these guidelines:
101101
2. If the pull request adds functionality, the docs should be updated. Put
102102
your new functionality into a function with a docstring, and add the
103103
feature to the list in README.rst.
104-
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check
105-
https://travis-ci.org/alexmorozov/templated-docs/pull_requests
104+
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7 and for PyPy. Check
105+
https://travis-ci.org/kiawin/templated-docs/pull_requests
106106
and make sure that the tests pass for all supported Python versions.
107107

108108
Tips
@@ -112,3 +112,4 @@ To run a subset of tests::
112112

113113

114114
$ python -m unittest tests.test_templated_docs
115+

README.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ Templated-docs
44

55

66
.. image:: https://badge.fury.io/py/templated-docs.svg
7-
:target: https://pypi.python.org/pypi/templated_docs
7+
:target: https://pypi.python.org/pypi/templateddocs
88

9-
.. image:: https://img.shields.io/travis/alexmorozov/templated-docs.svg
10-
:target: https://travis-ci.org/alexmorozov/templated-docs
9+
.. image:: https://img.shields.io/travis/kiawin/templated-docs.svg
10+
:target: https://travis-ci.org/kiawin/templated-docs
1111

1212
.. image:: https://readthedocs.org/projects/templated-docs/badge/?version=latest
1313
:target: https://templated-docs.readthedocs.io/en/latest/?badge=latest
1414
:alt: Documentation Status
1515

16-
.. image:: https://requires.io/github/alexmorozov/templated-docs/requirements.svg?branch=master
17-
:target: https://requires.io/github/alexmorozov/templated-docs/requirements?branch=master
16+
.. image:: https://requires.io/github/kiawin/templated-docs/requirements.svg?branch=master
17+
:target: https://requires.io/github/kiawin/templated-docs/requirements?branch=master
1818
:alt: Dependencies
1919

2020

@@ -41,7 +41,7 @@ Example usage
4141
Create a ``sample.odt`` document (make sure it's in OpenDocument format) and
4242
put it in your Django templates folder. It should look something like this:
4343

44-
.. image:: https://github.com/alexmorozov/templated-docs/raw/master/docs/document-template.png
44+
.. image:: https://github.com/kiawin/templated-docs/raw/master/docs/document-template.png
4545

4646
Then write a view to generate documents from this template:
4747

@@ -63,7 +63,7 @@ Then write a view to generate documents from this template:
6363
6464
Navigate to the url your view is connected to, and you'll see a rendered and converted document:
6565

66-
.. image:: https://github.com/alexmorozov/templated-docs/raw/master/docs/generated-document.png
66+
.. image:: https://github.com/kiawin/templated-docs/raw/master/docs/generated-document.png
6767

6868
For more examples, see the ``examples/`` subfolder in the repository. More detailed documentation is available on https://templated-docs.readthedocs.io.
6969

@@ -72,6 +72,8 @@ Credits
7272

7373
Templated-docs was written by `Alex Morozov`_.
7474

75+
As the repository is left idle for 2 years, `Sian Lerk Lau` has forked and resume the task of updating the module.
76+
7577
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
7678

7779
.. _Cookiecutter: https://github.com/audreyr/cookiecutter

requirements_dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
pip==8.1.2
1+
pip==18.0.0
22
bumpversion==0.5.3
33
wheel==0.29.0
44
watchdog==0.8.3
55
flake8==2.6.2
66
tox==2.3.1
77
coverage==4.1
88
Sphinx>=1.4,<1.5
9-
cryptography==1.4
9+
cryptography==2.3.1
1010
PyYAML==3.11

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.1
2+
current_version = 0.3.2
33
commit = True
44
tag = True
55
tag_name = {new_version}

setup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
]
2222

2323
setup(
24-
name='templated_docs',
25-
version='0.3.1',
24+
name='templateddocs',
25+
version='0.3.2',
2626
description=('Generate PDF, MS Word and Excel documents from templates '
2727
'in Django.'),
2828
long_description=readme + '\n\n' + history,
29-
author="Alex Morozov",
30-
author_email='alex@morozov.ca',
31-
url='https://github.com/alexmorozov/templated-docs',
29+
author="Sian Lerk Lau",
30+
author_email='kiawin@gmail.com',
31+
url='https://github.com/kiawin/templated-docs',
3232
packages=find_packages(),
3333
include_package_data=True,
3434
install_requires=requirements,
3535
license="MIT license",
3636
zip_safe=False,
37-
keywords='templated_docs',
37+
keywords='templateddocs',
3838
classifiers=[
3939
'Development Status :: 2 - Pre-Alpha',
4040
'Intended Audience :: Developers',
@@ -46,6 +46,8 @@
4646
'Programming Language :: Python :: 3.3',
4747
'Programming Language :: Python :: 3.4',
4848
'Programming Language :: Python :: 3.5',
49+
'Programming Language :: Python :: 3.6',
50+
'Programming Language :: Python :: 3.7',
4951
],
5052
test_suite='tests.test_app.tests',
5153
tests_require=test_requirements

templated_docs/__init__.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import logging
2525
log = logging.getLogger(__name__)
2626

27-
__version__ = '0.3.1'
27+
__version__ = '0.3.2'
2828

2929

3030
IMAGES_CONTEXT_KEY = '_templated_docs_imgs'
@@ -77,7 +77,7 @@ def find_template_file(template_name):
7777
raise TemplateDoesNotExist(template_name)
7878

7979

80-
def _convert_subprocess(filename, format, result_queue):
80+
def _convert_subprocess(filename, format, result_queue, options=None):
8181
"""
8282
Subprocess helper to convert a file via LOKit.
8383
@@ -93,16 +93,30 @@ def _convert_subprocess(filename, format, result_queue):
9393
conv_file = NamedTemporaryFile(delete=False,
9494
suffix='.%s' % format)
9595
with lo.documentLoad(filename) as doc:
96-
doc.saveAs(str(conv_file.name))
96+
doc.saveAs(str(conv_file.name), options=options)
9797
os.unlink(filename)
9898
result_queue.put(conv_file.name)
9999

100100

101-
def fill_template(template_name, context, output_format='odt'):
102-
"""
103-
Fill a document with data and convert it to the requested format.
101+
def fill_template(template_name, context, output_format='odt', options=None):
102+
"""Fill a document with data and convert it to the requested format.
104103
105104
Returns an absolute path to the generated file.
105+
106+
Supported output format:
107+
Text documents: doc, docx, fodt, html, odt, ott, pdf, txt, xhtml, png
108+
Spreadsheets: csv, fods, html, ods, ots, pdf, xhtml, xls, xlsx, png
109+
Presentations: fodp, html, odg, odp, otp, pdf, potm, pot, pptx, pps, ppt, svg, swf, xhtml, png
110+
Drawings: fodg, html, odg, pdf, svg, swf, xhtml, png
111+
112+
More on filter options, https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
113+
114+
:param template_name: the path to template, in OpenDocument format
115+
:param context: the context to be used to inject content
116+
:param output_format: the output format
117+
:param options: value of filterOptions in libreofficekit
118+
119+
:return:
106120
"""
107121

108122
if not isinstance(context, Context):
@@ -151,7 +165,7 @@ def fill_template(template_name, context, output_format='odt'):
151165
if source_extension[1:] != output_format:
152166
results = Queue()
153167
convertor = Process(target=_convert_subprocess,
154-
args=(str(dest_file.name), output_format, results))
168+
args=(str(dest_file.name), output_format, results, options))
155169
convertor.start()
156170
return results.get()
157171
else:

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ envlist = py{27,34}-django{18,19,110}, flake8
44
[testenv:flake8]
55
deps=flake8
66
commands=flake8 templated_docs
7+
max-line-length=120
78

89
[testenv]
910
passenv = LO_PATH

travis_pypi_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from urllib.request import urlopen
2222

2323

24-
GITHUB_REPO = 'alexmorozov/templated-docs'
24+
GITHUB_REPO = 'kiawin/templated-docs'
2525
TRAVIS_CONFIG_FILE = os.path.join(
2626
os.path.dirname(os.path.abspath(__file__)), '.travis.yml')
2727

0 commit comments

Comments
 (0)