[fixes] for translation and save full url for 404
This commit is contained in:
parent
6724c0cc29
commit
863aebcc78
3 changed files with 10 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue