From 2280558303a0e267fcd708aa14cdef8538766bae Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 15 Aug 2020 19:27:31 +1000 Subject: [PATCH] Add a method of return raw LaTeX for debugging --- InvenTree/report/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 93f1f1a95f..c85fe8878f 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -29,11 +29,20 @@ except OSError as err: if settings.LATEX_ENABLED: try: from django_tex.shortcuts import render_to_pdf + from django_tex.core import render_template_with_context except OSError as err: print("OSError: {e}".format(e=err)) print("You may not have a working LaTeX toolchain installed?") sys.exit(1) +from django.http import HttpResponse + +class TexResponse(HttpResponse): + def __init__(self, content, filename=None): + super().__init__(content_type="application/txt") + self["Content-Disposition"] = 'filename="{}"'.format(filename) + self.write(content) + def rename_template(instance, filename): @@ -154,6 +163,8 @@ class ReportTemplateBase(models.Model): if self.extension == '.tex': # Render LaTeX template to PDF if settings.LATEX_ENABLED: + rendered = render_template_with_context(self.template_name, context) + #return TexResponse(rendered, filename="raw.tex") return render_to_pdf(request, self.template_name, context, filename=filename) else: return ValidationError("Enable LaTeX support in config.yaml")