From 5f9348cd0509ca9c799542a70adcde4f807830db Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 23 May 2019 17:52:22 +0200 Subject: Document generation: display an error page for template error --- ishtar_common/models.py | 4 +++- ishtar_common/templates/500.html | 2 ++ ishtar_common/templates/error.html | 6 ++++++ ishtar_common/views.py | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ishtar_common/templates/error.html diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 8e5983a45..032004e2f 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -25,7 +25,7 @@ from collections import OrderedDict import datetime import inspect from importlib import import_module -from jinja2 import TemplateSyntaxError +from jinja2 import TemplateSyntaxError, UndefinedError import json import logging import os @@ -3201,6 +3201,8 @@ class DocumentTemplate(models.Model): result = engine.render(self.template, **values) except TemplateSyntaxError as e: raise TemplateSyntaxError(str(e), e.lineno) + except UndefinedError as e: + raise TemplateSyntaxError(str(e), 0) output = open(output_name, 'wb') output.write(result) return output_name diff --git a/ishtar_common/templates/500.html b/ishtar_common/templates/500.html index f48c2393d..9815a17f4 100644 --- a/ishtar_common/templates/500.html +++ b/ishtar_common/templates/500.html @@ -19,8 +19,10 @@
{% block content %} + {% block error %}

{% trans "An error has occured. The support team has been warned." %}

{% endblock %} + {% endblock %}

{% trans "Back to main page" %}