Bläddra i källkod

Validate jinja2 syntax before saving print format

version-14
Pratik Vyas 10 år sedan
förälder
incheckning
79ce25d44a
1 ändrade filer med 7 tillägg och 0 borttagningar
  1. +7
    -0
      frappe/core/doctype/print_format/print_format.py

+ 7
- 0
frappe/core/doctype/print_format/print_format.py Visa fil

@@ -4,6 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import frappe.utils import frappe.utils
from jinja2 import TemplateSyntaxError


from frappe.model.document import Document from frappe.model.document import Document


@@ -16,6 +17,12 @@ class PrintFormat(Document):
self.old_doc_type = frappe.db.get_value('Print Format', self.old_doc_type = frappe.db.get_value('Print Format',
self.name, 'doc_type') 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): def on_update(self):
if hasattr(self, 'old_doc_type') and self.old_doc_type: if hasattr(self, 'old_doc_type') and self.old_doc_type:
frappe.clear_cache(doctype=self.old_doc_type) frappe.clear_cache(doctype=self.old_doc_type)


Laddar…
Avbryt
Spara