Merge pull request #920 from pdvyas/validate-jinja-template

Validate jinja2 syntax before saving print format
This commit is contained in:
Rushabh Mehta 2014-11-25 10:47:53 +05:30
commit 41adcfad1b
2 changed files with 9 additions and 1 deletions

View file

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
import frappe.utils
from jinja2 import TemplateSyntaxError
from frappe.model.document import Document
@ -16,6 +17,12 @@ class PrintFormat(Document):
self.old_doc_type = frappe.db.get_value('Print Format',
self.name, 'doc_type')
jenv = frappe.get_jenv()
try:
jenv.from_string(self.html)
except TemplateSyntaxError:
frappe.throw(frappe._("Syntax error in Jinja template"))
def on_update(self):
if hasattr(self, 'old_doc_type') and self.old_doc_type:
frappe.clear_cache(doctype=self.old_doc_type)

View file

@ -3,6 +3,7 @@
"doctype": "Print Format",
"name": "_Test Print Format 1",
"module": "core",
"doc_type": "User"
"doc_type": "User",
"html": ""
}
]