Add a method of return raw LaTeX for debugging

This commit is contained in:
Oliver Walters 2020-08-15 19:27:31 +10:00
parent 1f5d81ef93
commit 2280558303

View File

@ -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")