Browse Source

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

version-14
Anand Doshi 11 years ago
parent
commit
11c0dae36f
2 changed files with 17 additions and 6 deletions
  1. +12
    -2
      frappe/templates/pages/print.py
  2. +5
    -4
      frappe/utils/data.py

+ 12
- 2
frappe/templates/pages/print.py View File

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

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

no_cache = 1
@@ -144,7 +144,7 @@ def make_layout(doc, meta):
if df.fieldtype=="HTML" and df.options:
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)

# if table, add the row info in the field
@@ -176,6 +176,16 @@ def is_visible(df):
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

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):
print_settings = frappe.get_doc("Print Settings")



+ 5
- 4
frappe/utils/data.py View File

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


# from Jinja2 code
_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)')
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):
html_escape_table = {


Loading…
Cancel
Save