Ver código fonte

Add is_image util (#4605)

version-14
Faris Ansari 7 anos atrás
committed by Nabin Hait
pai
commit
49b63d7680
2 arquivos alterados com 8 adições e 1 exclusões
  1. +1
    -1
      frappe/templates/print_formats/standard_macros.html
  2. +7
    -0
      frappe/utils/data.py

+ 1
- 1
frappe/templates/print_formats/standard_macros.html Ver arquivo

@@ -112,7 +112,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}"
<img src="{{ doc[df.fieldname] }}" class="signature-img img-responsive"
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}>
{% 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"
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}>
{% elif df.fieldtype=="HTML" %}


+ 7
- 0
frappe/utils/data.py Ver arquivo

@@ -516,6 +516,13 @@ def is_html(text):
break
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
_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)')


Carregando…
Cancelar
Salvar