mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a method of return raw LaTeX for debugging
This commit is contained in:
parent
1f5d81ef93
commit
2280558303
@ -29,11 +29,20 @@ except OSError as err:
|
|||||||
if settings.LATEX_ENABLED:
|
if settings.LATEX_ENABLED:
|
||||||
try:
|
try:
|
||||||
from django_tex.shortcuts import render_to_pdf
|
from django_tex.shortcuts import render_to_pdf
|
||||||
|
from django_tex.core import render_template_with_context
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
print("OSError: {e}".format(e=err))
|
print("OSError: {e}".format(e=err))
|
||||||
print("You may not have a working LaTeX toolchain installed?")
|
print("You may not have a working LaTeX toolchain installed?")
|
||||||
sys.exit(1)
|
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):
|
def rename_template(instance, filename):
|
||||||
|
|
||||||
@ -154,6 +163,8 @@ class ReportTemplateBase(models.Model):
|
|||||||
if self.extension == '.tex':
|
if self.extension == '.tex':
|
||||||
# Render LaTeX template to PDF
|
# Render LaTeX template to PDF
|
||||||
if settings.LATEX_ENABLED:
|
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)
|
return render_to_pdf(request, self.template_name, context, filename=filename)
|
||||||
else:
|
else:
|
||||||
return ValidationError("Enable LaTeX support in config.yaml")
|
return ValidationError("Enable LaTeX support in config.yaml")
|
||||||
|
Loading…
Reference in New Issue
Block a user