From 251a23d1275fe05137710b8d3b0fe993149a2d7d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 22 May 2020 00:09:51 +1000 Subject: [PATCH] Cleanup --- InvenTree/InvenTree/settings.py | 4 +++- InvenTree/config_template.yaml | 2 ++ InvenTree/report/models.py | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e325e092da..8e4feade23 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -203,7 +203,7 @@ TEMPLATES = [ # Backend for LaTeX report rendering { 'NAME': 'tex', - 'BACKEND': 'django_tex.engine.TeXEngine', + 'BACKEND': 'django_tex.engine.TeXEngine', 'DIRS': [ os.path.join(MEDIA_ROOT, 'report'), ] @@ -356,6 +356,8 @@ latex_settings = CONFIG.get('latex', {}) # Set the latex interpreter in the config.yaml settings file LATEX_INTERPRETER = latex_settings.get('interpreter', 'pdflatex') +LATEX_INTERPRETER_OPTIONS = latex_settings.get('options', '') + LATEX_GRAPHICSPATH = [ # Allow LaTeX files to access the report assets directory os.path.join(MEDIA_ROOT, "report", "assets"), diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 686f910fbf..b5446b8e89 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -82,3 +82,5 @@ latex: # Note: The intepreter needs to be installed on the system! # e.g. to install pdflatx: apt-get texlive-latex-base interpreter: pdflatex + # Extra options to pass through to the LaTeX interpreter + options: '' \ No newline at end of file diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 1e30fd1c3e..a2dae298e7 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -54,7 +54,14 @@ class ReportTemplate(models.Model): def template_name(self): return os.path.join('report_template', os.path.basename(self.template.name)) - def render(self, request, context={}, **kwargs): + def get_context_data(self, request): + """ + Supply context data to the template for rendering + """ + + return {} + + def render(self, request, **kwargs): """ Render the template to a PDF file. @@ -65,15 +72,18 @@ class ReportTemplate(models.Model): filename = kwargs.get('filename', 'report.pdf') + context = self.get_context_data(request) + context['request'] = request if self.extension == '.tex': + # Render LaTeX template to PDF return render_to_pdf(request, self.template_name, context, filename=filename) elif self.extension in ['.htm', '.html']: + # Render HTML template to PDF wp = WeasyprintReportMixin(request, self.template_name, **kwargs) return wp.render_to_response(context, **kwargs) - name = models.CharField( blank=False, max_length=100, help_text=_('Template name'),