diff options
| -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'} | 
