mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #833 from SchrodingersGat/latex-fix
Catch some errors related to missing system packages
This commit is contained in:
commit
835451c02c
@ -351,12 +351,15 @@ DATE_INPUT_FORMATS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# LaTeX rendering settings (django-tex)
|
# LaTeX rendering settings (django-tex)
|
||||||
latex_settings = CONFIG.get('latex', {})
|
LATEX_SETTINGS = CONFIG.get('latex', {})
|
||||||
|
|
||||||
|
# Is LaTeX rendering enabled? (Off by default)
|
||||||
|
LATEX_ENABLED = LATEX_SETTINGS.get('enabled', False)
|
||||||
|
|
||||||
# Set the latex interpreter in the config.yaml settings file
|
# Set the latex interpreter in the config.yaml settings file
|
||||||
LATEX_INTERPRETER = latex_settings.get('interpreter', 'pdflatex')
|
LATEX_INTERPRETER = LATEX_SETTINGS.get('interpreter', 'pdflatex')
|
||||||
|
|
||||||
LATEX_INTERPRETER_OPTIONS = latex_settings.get('options', '')
|
LATEX_INTERPRETER_OPTIONS = LATEX_SETTINGS.get('options', '')
|
||||||
|
|
||||||
LATEX_GRAPHICSPATH = [
|
LATEX_GRAPHICSPATH = [
|
||||||
# Allow LaTeX files to access the report assets directory
|
# Allow LaTeX files to access the report assets directory
|
||||||
|
@ -77,10 +77,12 @@ sentry:
|
|||||||
# LaTeX report rendering
|
# LaTeX report rendering
|
||||||
# InvenTree uses the django-tex plugin to enable LaTeX report rendering
|
# InvenTree uses the django-tex plugin to enable LaTeX report rendering
|
||||||
# Ref: https://pypi.org/project/django-tex/
|
# Ref: https://pypi.org/project/django-tex/
|
||||||
|
# Note: Ensure that a working LaTeX toolchain is installed and working *before* starting the server
|
||||||
latex:
|
latex:
|
||||||
# Select the LaTeX interpreter to use for PDF rendering
|
# Select the LaTeX interpreter to use for PDF rendering
|
||||||
# Note: The intepreter needs to be installed on the system!
|
# Note: The intepreter needs to be installed on the system!
|
||||||
# e.g. to install pdflatex: apt-get texlive-latex-base
|
# e.g. to install pdflatex: apt-get texlive-latex-base
|
||||||
|
enabled: False
|
||||||
interpreter: pdflatex
|
interpreter: pdflatex
|
||||||
# Extra options to pass through to the LaTeX interpreter
|
# Extra options to pass through to the LaTeX interpreter
|
||||||
options: ''
|
options: ''
|
@ -6,8 +6,11 @@ Report template model definitions
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.core.validators import FileExtensionValidator
|
from django.core.validators import FileExtensionValidator
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
@ -15,8 +18,21 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from part import models as PartModels
|
from part import models as PartModels
|
||||||
|
|
||||||
from django_tex.shortcuts import render_to_pdf
|
try:
|
||||||
from django_weasyprint import WeasyTemplateResponseMixin
|
from django_weasyprint import WeasyTemplateResponseMixin
|
||||||
|
except OSError as err:
|
||||||
|
print("OSError: {e}".format(e=err))
|
||||||
|
print("You may require some further system packages to be installed.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Conditional import if LaTeX templating is enabled
|
||||||
|
if settings.LATEX_ENABLED:
|
||||||
|
try:
|
||||||
|
from django_tex.shortcuts import render_to_pdf
|
||||||
|
except OSError as err:
|
||||||
|
print("OSError: {e}".format(e=err))
|
||||||
|
print("You may not have a working LaTeX toolchain installed?")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def rename_template(instance, filename):
|
def rename_template(instance, filename):
|
||||||
@ -137,7 +153,10 @@ 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:
|
||||||
return render_to_pdf(request, self.template_name, context, filename=filename)
|
return render_to_pdf(request, self.template_name, context, filename=filename)
|
||||||
|
else:
|
||||||
|
return ValidationError("Enable LaTeX support in config.yaml")
|
||||||
elif self.extension in ['.htm', '.html']:
|
elif self.extension in ['.htm', '.html']:
|
||||||
# Render HTML template to PDF
|
# Render HTML template to PDF
|
||||||
wp = WeasyprintReportMixin(request, self.template_name, **kwargs)
|
wp = WeasyprintReportMixin(request, self.template_name, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user