diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-09-28 17:42:02 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-09-28 17:42:02 +0200 |
commit | 4fcafb2275f1f4fe366fb4ac5e162e938ff65a75 (patch) | |
tree | 8e3f802bfbc43513efed4692087a26cb3f0a66f6 /archaeological_operations/views.py | |
parent | 65891cf11bf454fa3f8d23b79b7eca40bdfc88c5 (diff) | |
download | Ishtar-4fcafb2275f1f4fe366fb4ac5e162e938ff65a75.tar.bz2 Ishtar-4fcafb2275f1f4fe366fb4ac5e162e938ff65a75.zip |
Catch template syntax error on documet generation
Diffstat (limited to 'archaeological_operations/views.py')
-rw-r--r-- | archaeological_operations/views.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 858043c82..48d7c4a4f 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -18,6 +18,7 @@ # See the file COPYING for details. import json +from jinja2 import TemplateSyntaxError from django.conf import settings from django.core.urlresolvers import reverse @@ -48,7 +49,8 @@ from archaeological_operations.wizards import has_associated_file, \ SiteDeletionWizard, OperationSearch from ishtar_common.forms import ClosingDateFormSelection, FinalForm, \ FinalDeleteForm -from ishtar_common.models import get_current_profile, IshtarSiteProfile +from ishtar_common.models import get_current_profile, IshtarSiteProfile, \ + DocumentTemplate from ishtar_common.utils import put_session_message, check_rights_condition from ishtar_common.views_item import get_item, show_item, revert_item, new_item from ishtar_common.wizards import SearchWizard @@ -530,10 +532,26 @@ def administrativeactfile_document( dct['template_form'] = DocumentGenerationAdminActForm( request.POST, document_type=document_type, obj=c_object) if dct['template_form'].is_valid(): - return generatedoc_administrativeactop( - request, - dct['search_form'].cleaned_data.get('pk'), - dct['template_form'].cleaned_data.get('document_template')) + try: + return generatedoc_administrativeactop( + request, + dct['search_form'].cleaned_data.get('pk'), + dct['template_form'].cleaned_data.get( + 'document_template')) + except TemplateSyntaxError: + dct['search_form'] = search_form() + try: + template = DocumentTemplate.objects.get(pk=dct[ + 'template_form'].cleaned_data.get( + 'document_template')).name + except DocumentTemplate.DoesNotExist: + template = "" + dct['template_form'] = DocumentGenerationAdminActForm( + document_type=document_type) + dct['template_error'] = unicode(_( + u"Syntax error on the source template \"{}\" - " + u"contact your administrator and ask him to check " + u"the syntax of this document.")).format(template) else: dct['search_form'] = search_form() dct['template_form'] = DocumentGenerationAdminActForm( |