diff --git a/frappe/model/utils/__init__.py b/frappe/model/utils/__init__.py index 8600c64db9..a2aed5c00e 100644 --- a/frappe/model/utils/__init__.py +++ b/frappe/model/utils/__init__.py @@ -7,6 +7,7 @@ from frappe.utils import cstr from frappe.build import html_to_js_template import re + """ Model utilities, unclassified functions """ @@ -32,6 +33,8 @@ def set_field_property(filters, key, value): frappe.db.commit() +class InvalidIncludePath(frappe.ValidationError): pass + def render_include(content): '''render {% raw %}{% include "app/path/filename" %}{% endraw %} in js file''' @@ -42,7 +45,7 @@ def render_include(content): if "{% include" in content: paths = re.findall(r'''{% include\s['"](.*)['"]\s%}''', content) if not paths: - frappe.throw('Invalid include path') + frappe.throw('Invalid include path', InvalidIncludePath) for path in paths: app, app_path = path.split('/', 1) diff --git a/frappe/translate.py b/frappe/translate.py index 4ff9d9762d..ea7db8b4d5 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -11,7 +11,7 @@ from __future__ import unicode_literals """ import frappe, os, re, codecs, json -from frappe.model.utils import render_include +from frappe.model.utils import render_include, InvalidIncludePath from frappe.utils import strip from jinja2 import TemplateError import itertools, operator @@ -431,7 +431,8 @@ def _get_messages_from_page_or_report(doctype, name, module=None): return messages def get_server_messages(app): - """Extracts all translatable strings (tagged with :func:`frappe._`) from Python modules inside an app""" + """Extracts all translatable strings (tagged with :func:`frappe._`) from Python modules + inside an app""" messages = [] for basepath, folders, files in os.walk(frappe.get_pymodule_path(app)): for dontwalk in (".git", "public", "locale"): @@ -487,7 +488,7 @@ def extract_messages_from_code(code, is_py=False): :param is_py: include messages in triple quotes e.g. `_('''message''')`""" try: code = render_include(code) - except TemplateError: + except (TemplateError, ImportError, InvalidIncludePath): # Exception will occur when it encounters John Resig's microtemplating code pass diff --git a/frappe/website/render.py b/frappe/website/render.py index db1f7075e1..3edf8ef5f3 100644 --- a/frappe/website/render.py +++ b/frappe/website/render.py @@ -23,7 +23,7 @@ def render(path=None, http_status_code=None): data = None # if in list of already known 404s, send it - if can_cache() and frappe.cache().hget('website_404', path): + if can_cache() and frappe.cache().hget('website_404', frappe.request.url): data = render_page('404') http_status_code = 404 @@ -41,7 +41,7 @@ def render(path=None, http_status_code=None): frappe.local.form_dict.doctype = doctype else: # 404s are expensive, cache them! - frappe.cache().hset('website_404', path, True) + frappe.cache().hset('website_404', frappe.request.url, True) data = render_page('404') http_status_code = 404