浏览代码

[print] Strip html tags and check if field has value for strings

version-14
Anand Doshi 11 年前
父节点
当前提交
11c0dae36f
共有 2 个文件被更改,包括 17 次插入6 次删除
  1. +12
    -2
      frappe/templates/pages/print.py
  2. +5
    -4
      frappe/utils/data.py

+ 12
- 2
frappe/templates/pages/print.py 查看文件

@@ -8,7 +8,7 @@ from frappe import _


from frappe.modules import get_doc_path from frappe.modules import get_doc_path
from jinja2 import TemplateNotFound from jinja2 import TemplateNotFound
from frappe.utils import cint
from frappe.utils import cint, strip_html
from frappe.utils.pdf import get_pdf from frappe.utils.pdf import get_pdf


no_cache = 1 no_cache = 1
@@ -144,7 +144,7 @@ def make_layout(doc, meta):
if df.fieldtype=="HTML" and df.options: if df.fieldtype=="HTML" and df.options:
doc.set(df.fieldname, True) # show this field doc.set(df.fieldname, True) # show this field


if is_visible(df) and doc.get(df.fieldname) not in (None, ""):
if is_visible(df) and has_value(df, doc):
page[-1][-1].append(df) page[-1][-1].append(df)


# if table, add the row info in the field # if table, add the row info in the field
@@ -176,6 +176,16 @@ def is_visible(df):
no_display = ("Section Break", "Column Break", "Button") no_display = ("Section Break", "Column Break", "Button")
return (df.fieldtype not in no_display) and not df.get("__print_hide") and not df.print_hide return (df.fieldtype not in no_display) and not df.get("__print_hide") and not df.print_hide


def has_value(df, doc):
value = doc.get(df.fieldname)
if value in (None, ""):
return False

elif isinstance(value, basestring) and not strip_html(value).strip():
return False

return True

def get_print_style(style=None): def get_print_style(style=None):
print_settings = frappe.get_doc("Print Settings") print_settings = frappe.get_doc("Print Settings")




+ 5
- 4
frappe/utils/data.py 查看文件

@@ -417,11 +417,12 @@ def is_html(text):
break break
return out return out



# from Jinja2 code
_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)')
def strip_html(text): def strip_html(text):
"""
removes anything enclosed in and including <>
"""
return re.compile(r'<.*?>').sub('', text)
"""removes anything enclosed in and including <>"""
return _striptags_re.sub("", text)


def escape_html(text): def escape_html(text):
html_escape_table = { html_escape_table = {


正在加载...
取消
保存