Revoke support for LaTex reporting

This commit is contained in:
Oliver Walters 2021-02-04 16:18:28 +11:00
parent 264bd625d3
commit 59904ace1d
5 changed files with 35 additions and 81 deletions

View File

@ -208,7 +208,6 @@ INSTALLED_APPS = [
'mptt', # Modified Preorder Tree Traversal
'markdownx', # Markdown editing
'markdownify', # Markdown template rendering
'django_tex', # LaTeX output
'django_admin_shell', # Python shell for the admin interface
'djmoney', # django-money integration
'djmoney.contrib.exchange', # django-money exchange rates
@ -265,14 +264,6 @@ TEMPLATES = [
],
},
},
# Backend for LaTeX report rendering
{
'NAME': 'tex',
'BACKEND': 'django_tex.engine.TeXEngine',
'DIRS': [
os.path.join(MEDIA_ROOT, 'report'),
]
},
]
REST_FRAMEWORK = {
@ -485,22 +476,6 @@ DATE_INPUT_FORMATS = [
"%Y-%m-%d",
]
# LaTeX rendering settings (django-tex)
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
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"),
]
# crispy forms use the bootstrap templates
CRISPY_TEMPLATE_PACK = 'bootstrap3'

View File

@ -107,19 +107,6 @@ static_root: '../inventree_static'
# If unspecified, the local user's temp directory will be used
#backup_dir: '/home/inventree/backup/'
# LaTeX report rendering
# InvenTree uses the django-tex plugin to enable LaTeX report rendering
# Ref: https://pypi.org/project/django-tex/
# Note: Ensure that a working LaTeX toolchain is installed and working *before* starting the server
latex:
# Select the LaTeX interpreter to use for PDF rendering
# Note: The intepreter needs to be installed on the system!
# e.g. to install pdflatex: apt-get texlive-latex-base
enabled: False
interpreter: pdflatex
# Extra options to pass through to the LaTeX interpreter
options: ''
# Permit custom authentication backends
#authentication_backends:
# - 'django.contrib.auth.backends.ModelBackend'

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.7 on 2021-02-04 05:17
import django.core.validators
from django.db import migrations, models
import report.models
class Migration(migrations.Migration):
dependencies = [
('report', '0006_reportsnippet'),
]
operations = [
migrations.AlterField(
model_name='testreport',
name='template',
field=models.FileField(help_text='Report template file', upload_to=report.models.rename_template, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'htm'])], verbose_name='Template'),
),
]

View File

@ -14,7 +14,6 @@ from django.db import models
from django.conf import settings
from django.core.validators import FileExtensionValidator
from django.core.exceptions import ValidationError
import stock.models
@ -29,17 +28,6 @@ except OSError as 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
from django_tex.core import render_template_with_context
from django_tex.exceptions import TexError
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
@ -104,7 +92,7 @@ class ReportBase(models.Model):
def template_name(self):
"""
Returns the file system path to the template file.
Required for passing the file to an external process (e.g. LaTeX)
Required for passing the file to an external process
"""
template = os.path.join('report_template', self.getSubdir(), os.path.basename(self.template.name))
@ -124,7 +112,7 @@ class ReportBase(models.Model):
upload_to=rename_template,
verbose_name=_('Template'),
help_text=_("Report template file"),
validators=[FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])],
validators=[FileExtensionValidator(allowed_extensions=['html', 'htm'])],
)
description = models.CharField(
@ -153,12 +141,11 @@ class ReportTemplateBase(ReportBase):
"""
Render the template to a PDF file.
Supported template formats:
.tex - Uses django-tex plugin to render LaTeX template against an installed LaTeX engine
.html - Uses django-weasyprint plugin to render HTML template against Weasyprint
Uses django-weasyprint plugin to render HTML template against Weasyprint
"""
filename = kwargs.get('filename', 'report.pdf')
# TODO: Support custom filename generation!
# filename = kwargs.get('filename', 'report.pdf')
context = self.get_context_data(request)
@ -171,31 +158,17 @@ class ReportTemplateBase(ReportBase):
context['date'] = datetime.datetime.now().date()
context['datetime'] = datetime.datetime.now()
if self.extension == '.tex':
# Render LaTeX template to PDF
if settings.LATEX_ENABLED:
# Attempt to render to LaTeX template
# If there is a rendering error, return the (partially rendered) template,
# so at least we can debug what is going on
try:
rendered = render_template_with_context(self.template_name, context)
return render_to_pdf(request, self.template_name, context, filename=filename)
except TexError:
return TexResponse(rendered, filename="error.tex")
else:
raise ValidationError("Enable LaTeX support in config.yaml")
elif self.extension in ['.htm', '.html']:
# Render HTML template to PDF
wp = WeasyprintReportMixin(
request,
self.template_name,
base_url=request.build_absolute_uri("/"),
presentational_hints=True,
**kwargs)
# Render HTML template to PDF
wp = WeasyprintReportMixin(
request,
self.template_name,
base_url=request.build_absolute_uri("/"),
presentational_hints=True,
**kwargs)
return wp.render_to_response(
context,
**kwargs)
return wp.render_to_response(
context,
**kwargs)
enabled = models.BooleanField(
default=True,

View File

@ -23,7 +23,6 @@ coverage==5.3 # Unit test coverage
coveralls==2.1.2 # Coveralls linking (for Travis)
rapidfuzz==0.7.6 # Fuzzy string matching
django-stdimage==5.1.1 # Advanced ImageField management
django-tex==1.1.7 # LaTeX PDF export
django-weasyprint==1.0.1 # HTML PDF export
django-debug-toolbar==2.2 # Debug / profiling toolbar
django-admin-shell==0.1.2 # Python shell for the admin interface