@@ -14,7 +14,7 @@ import os, sys, importlib, inspect, json | |||||
from .exceptions import * | from .exceptions import * | ||||
from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | ||||
__version__ = '9.2.22' | |||||
__version__ = '9.2.23' | |||||
__title__ = "Frappe Framework" | __title__ = "Frappe Framework" | ||||
local = Local() | local = Local() | ||||
@@ -545,6 +545,8 @@ frappe.utils = { | |||||
}, | }, | ||||
is_image_file: function(filename) { | is_image_file: function(filename) { | ||||
// url can have query params | |||||
filename = filename.split('?')[0]; | |||||
return (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(filename); | return (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(filename); | ||||
}, | }, | ||||
@@ -643,4 +645,4 @@ if (!Array.prototype.uniqBy) { | |||||
}) | }) | ||||
} | } | ||||
}) | }) | ||||
} | |||||
} |
@@ -118,7 +118,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" | |||||
<img src="{{ doc[df.fieldname] }}" class="signature-img img-responsive" | <img src="{{ doc[df.fieldname] }}" class="signature-img img-responsive" | ||||
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}> | {%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}> | ||||
{% elif df.fieldtype in ("Attach", "Attach Image") and doc[df.fieldname] | {% elif df.fieldtype in ("Attach", "Attach Image") and doc[df.fieldname] | ||||
and (guess_mimetype(doc[df.fieldname])[0] or "").startswith("image/") %} | |||||
and frappe.utils.is_image(doc[df.fieldname]) %} | |||||
<img src="{{ doc[df.fieldname] }}" class="img-responsive" | <img src="{{ doc[df.fieldname] }}" class="img-responsive" | ||||
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}> | {%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}> | ||||
{% elif df.fieldtype=="HTML" %} | {% elif df.fieldtype=="HTML" %} | ||||
@@ -371,12 +371,17 @@ def fmt_money(amount, precision=None, currency=None): | |||||
# 40,000 -> 40,000.00 | # 40,000 -> 40,000.00 | ||||
# 40,000.00000 -> 40,000.00 | # 40,000.00000 -> 40,000.00 | ||||
# 40,000.23000 -> 40,000.23 | # 40,000.23000 -> 40,000.23 | ||||
if decimal_str: | if decimal_str: | ||||
parts = str(amount).split(decimal_str) | parts = str(amount).split(decimal_str) | ||||
decimals = parts[1] if len(parts) > 1 else '' | decimals = parts[1] if len(parts) > 1 else '' | ||||
if precision > 2: | if precision > 2: | ||||
if len(decimals) < 3: | if len(decimals) < 3: | ||||
precision = 2 | |||||
if currency: | |||||
fraction = frappe.db.get_value("Currency", currency, "fraction_units") or 100 | |||||
precision = len(cstr(fraction)) - 1 | |||||
else: | |||||
precision = 2 | |||||
elif len(decimals) < precision: | elif len(decimals) < precision: | ||||
precision = len(decimals) | precision = len(decimals) | ||||
@@ -511,6 +516,13 @@ def is_html(text): | |||||
break | break | ||||
return out | return out | ||||
def is_image(filepath): | |||||
from mimetypes import guess_type | |||||
# filepath can be https://example.com/bed.jpg?v=129 | |||||
filepath = filepath.split('?')[0] | |||||
return (guess_type(filepath)[0] or "").startswith("image/") | |||||
# from Jinja2 code | # from Jinja2 code | ||||
_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)') | _striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)') | ||||