diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-05-23 17:52:22 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:28 +0200 |
commit | 5f9348cd0509ca9c799542a70adcde4f807830db (patch) | |
tree | 36cbe78806ca99e2dc0c6fa258bb1cec06223b3e | |
parent | 94981020c6acfb212e8326bb3f6a0feb362245e8 (diff) | |
download | Ishtar-5f9348cd0509ca9c799542a70adcde4f807830db.tar.bz2 Ishtar-5f9348cd0509ca9c799542a70adcde4f807830db.zip |
Document generation: display an error page for template error
-rw-r--r-- | ishtar_common/models.py | 4 | ||||
-rw-r--r-- | ishtar_common/templates/500.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/error.html | 6 | ||||
-rw-r--r-- | ishtar_common/views.py | 9 |
4 files changed, 20 insertions, 1 deletions
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 @@ </header> <div class="container"> {% block content %} + {% block error %} <h3>{% trans "An error has occured. The support team has been warned." %}</h3> {% endblock %} + {% endblock %} <p><a href='/'>{% trans "Back to main page" %}</a></p> </div> <div id="footer"> diff --git a/ishtar_common/templates/error.html b/ishtar_common/templates/error.html new file mode 100644 index 000000000..069796184 --- /dev/null +++ b/ishtar_common/templates/error.html @@ -0,0 +1,6 @@ +{% extends "500.html" %} +{% load i18n %} +{% block error %} +<h3>{{error_title}}</h3> +<p>{{error}}</p> +{% endblock %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index a10c44c77..98c538c66 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -20,6 +20,7 @@ import csv import datetime import importlib +from jinja2 import TemplateSyntaxError import json import logging import os @@ -34,6 +35,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse, NoReverseMatch from django.db.models import Q +from django.template import loader from django.forms.models import modelformset_factory from django.http import HttpResponse, Http404, HttpResponseRedirect, \ HttpResponseBadRequest, JsonResponse @@ -1892,6 +1894,13 @@ def gen_generate_doc(model): doc = item.publish(template_pk) except model.DoesNotExist: doc = None + except TemplateSyntaxError as e: + dct = { + "error_title": _("Error on your template"), + "error": str(e) + } + template = loader.get_template("error.html") + return HttpResponse(template.render(dct, request)) if doc: MIMES = {'odt': 'application/vnd.oasis.opendocument.text', 'ods': 'application/vnd.oasis.opendocument.spreadsheet'} |