basxsoftwareassociation / bread

Engine to create database applications based on Django and the IBM Carbon Design System
BSD 3-Clause "New" or "Revised" License
19 stars 2 forks source link

Contrib module for document templates #120

Closed saemideluxe closed 2 years ago

saemideluxe commented 2 years ago

For the ponds project we will need a way to let users create a document template which has placeholders that can be populated with values from the database. The output should then be a PDF or similar.

The following is needed to implement this:

The docx handling and the PDF generation are likely the more difficult issues. Important here is: The process needs to be doable on a headless linux system (no word installed). It would be nice if we would have no non-pip dependencies (e.g. libreoffice or pandoc binaries). I think for reading/filling out dotx templates that is not too much of a problem, but rendering to PDF (in the same process) might be more challenging to find something good. Pandoc would be great, but it seems to not have an official (native) API e.g. for non-commandline usage, which makes it much less ideal.

Also, we should keep an eye on what dependencies we have to add for this. Especially if they are not maintained. Instead of adding an unmaintained wrapper pip-package we better rewrite it inside bread or copy and adjust it with a reference to the original code.

Some links:

saemideluxe commented 2 years ago

Okay, after some more research dotx and mailmerge seem not be the best options, going with the docxtpl might be the best option. I haven't touched Word for many years now, so input from some experienced user might be helpfull as well...

saemideluxe commented 2 years ago

A nice thing for UX might be an inplace preview when editing a template, where the user can also quickly page through different objects to see how things would get rendered.

Another thought here: We could either let the user define fields with "variable names" which can then be used inside the template, or we can assume that the values inside the document template are valid field values. After giving it some thought I think the second option is the better one, as the template document will only need to be uploaded once in order to change how a value is displayed.

saemideluxe commented 2 years ago

Another note: This could be the occasion to think about a simple "formatting DSL" which gives some access to the ObjectFieldValue and/or bread.formatters.format_value features. Would also be usable in bread.contrib.reports. But low prio.

saemideluxe commented 2 years ago

Closing this for now, will need to test with real-use cases in ponds.