diff --git a/frappe/print/doctype/print_format/print_format.json b/frappe/print/doctype/print_format/print_format.json index 61bdc9316d..019091a016 100644 --- a/frappe/print/doctype/print_format/print_format.json +++ b/frappe/print/doctype/print_format/print_format.json @@ -281,6 +281,72 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "css_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "css", + "fieldtype": "Code", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Custom CSS", + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "custom_html_help", + "fieldtype": "HTML", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Custom HTML Help", + "no_copy": 0, + "options": "

Custom CSS Help

\n\n

Notes:

\n\n
    \n
  1. All field groups (label + value) are set attributes data-fieldtype and data-fieldname
  2. \n
  3. All values are given class value
  4. \n
  5. All Section Breaks are given class section-break
  6. \n
  7. All Column Breaks are given class column-break
  8. \n
\n\n

Examples

\n\n

1. Left align integers

\n\n
[data-fieldtype=\"Int\"] .value { text-left: left; }
\n\n

1. Add border to sections except the last section

\n\n
.section-break { padding: 30px 0px; border-bottom: 1px solid #eee; }\n.section-break:last-child { padding-bottom: 0px; border-bottom: 0px;  }
\n", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -381,7 +447,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2015-07-15 08:01:06.284031", + "modified": "2015-09-09 05:46:11.025962", "modified_by": "Administrator", "module": "Print", "name": "Print Format", diff --git a/frappe/print/doctype/print_format/test_print_format.py b/frappe/print/doctype/print_format/test_print_format.py index 936e06402c..aa8c79200d 100644 --- a/frappe/print/doctype/print_format/test_print_format.py +++ b/frappe/print/doctype/print_format/test_print_format.py @@ -12,7 +12,7 @@ class TestPrintFormat(unittest.TestCase): def test_print_user(self, style=None): print_html = frappe.get_print("User", "Administrator", style=style) self.assertTrue("" in print_html) - self.assertTrue(re.findall('
[\s]*Administrator[\s]*
', print_html)) + self.assertTrue(re.findall('
[\s]*Administrator[\s]*
', print_html)) return print_html def test_print_user_standard(self): diff --git a/frappe/templates/pages/print.html b/frappe/templates/pages/print.html index 0e69a533f4..6136426593 100644 --- a/frappe/templates/pages/print.html +++ b/frappe/templates/pages/print.html @@ -5,7 +5,10 @@ {{ title }} - + + diff --git a/frappe/templates/pages/print.py b/frappe/templates/pages/print.py index 46384d3496..9338adabd1 100644 --- a/frappe/templates/pages/print.py +++ b/frappe/templates/pages/print.py @@ -18,9 +18,6 @@ base_template_path = "templates/pages/print.html" standard_format = "templates/print_formats/standard.html" def get_context(context): - if not frappe.form_dict.format: - frappe.form_dict.format = standard_format - if not frappe.form_dict.doctype or not frappe.form_dict.name: return { "body": """

Error

@@ -31,14 +28,30 @@ def get_context(context): doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) meta = frappe.get_meta(doc.doctype) + print_format = get_print_format_doc() + return { - "body": get_html(doc, print_format = frappe.form_dict.format, - meta=meta, trigger_print = frappe.form_dict.trigger_print, no_letterhead=frappe.form_dict.no_letterhead), - "css": get_print_style(frappe.form_dict.style, frappe.form_dict.format), + "body": get_html(doc, print_format = print_format, + meta=meta, trigger_print = frappe.form_dict.trigger_print, + no_letterhead=frappe.form_dict.no_letterhead), + "css": get_print_style(frappe.form_dict.style, print_format), "comment": frappe.session.user, "title": doc.get(meta.title_field) if meta.title_field else doc.name } +def get_print_format_doc(print_format_name=None): + """Returns print format document""" + if not print_format_name: + print_format_name = frappe.form_dict.format or "Standard" + + if not print_format_name: + print_format_name = "Standard" + + if print_format_name == "Standard": + return None + else: + return frappe.get_doc("Print Format", print_format_name) + def get_html(doc, name=None, print_format=None, meta=None, no_letterhead=None, trigger_print=False): @@ -71,11 +84,7 @@ def get_html(doc, name=None, print_format=None, meta=None, format_data, format_data_map = [], {} # determine template - if print_format in ("Standard", standard_format): - template = "standard" - else: - print_format = frappe.get_doc("Print Format", print_format) - + if print_format: if print_format.standard=="Yes" or print_format.custom_format: template = jenv.from_string(get_print_format(doc.doctype, print_format)) @@ -97,8 +106,12 @@ def get_html(doc, name=None, print_format=None, meta=None, # fallback template = "standard" + else: + template = "standard" + + if template == "standard": - template = jenv.get_template("templates/print_formats/standard.html") + template = jenv.get_template(standard_format) args = { "doc": doc, @@ -119,6 +132,7 @@ def get_html(doc, name=None, print_format=None, meta=None, @frappe.whitelist() def get_html_and_style(doc, name=None, print_format=None, meta=None, no_letterhead=None, trigger_print=False): + print_format = get_print_format_doc(print_format) return { "html": get_html(doc, name=name, print_format=print_format, meta=meta, no_letterhead=no_letterhead, trigger_print=trigger_print), @@ -200,6 +214,10 @@ def make_layout(doc, meta, format_data=None): df.print_hide = 0 if df.fieldtype=="Section Break" or page==[]: + if len(page) > 1 and not any(page[-1]): + # truncate prev section if empty + del page[-1] + page.append([]) if df.fieldtype=="Column Break" or (page[-1]==[] and df.fieldtype!="Section Break"): @@ -232,9 +250,6 @@ def make_layout(doc, meta, format_data=None): df.end = None page[-1][-1].append(df) - # filter empty sections - layout = [filter(lambda s: any(filter(lambda c: any(c), s)), pg) for pg in layout] - return layout def is_visible(df, doc): @@ -256,6 +271,9 @@ def has_value(df, doc): elif isinstance(value, basestring) and not strip_html(value).strip(): return False + elif isinstance(value, list) and not len(value): + return False + return True def get_print_style(style=None, print_format=None, for_legacy=False): @@ -284,6 +302,9 @@ def get_print_style(style=None, print_format=None, for_legacy=False): # prepend css with at_import css = at_import + css + if print_format and print_format.css: + css += "\n\n" + print_format.css + return css def get_font(print_settings, print_format=None, for_legacy=False): @@ -292,8 +313,7 @@ def get_font(print_settings, print_format=None, for_legacy=False): return default font = None - if print_format and print_format not in ("Standard", standard_format): - print_format = frappe.get_doc("Print Format", print_format) + if print_format: if print_format.font and print_format.font!="Default": font = '{0}, sans-serif'.format(print_format.font) diff --git a/frappe/templates/print_formats/standard.html b/frappe/templates/print_formats/standard.html index fc0b121692..c2f5b6ea83 100644 --- a/frappe/templates/print_formats/standard.html +++ b/frappe/templates/print_formats/standard.html @@ -5,9 +5,9 @@
{{ add_header(loop.index, layout|len, doc, letter_head, no_letterhead) }} {% for section in page %} -
+
{% for column in section %} -
+
{% for df in column %} {{ render_field(df, doc) }} {% endfor %} diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index 9951252a25..4cea95bbd6 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -20,13 +20,13 @@ {%- if data -%} {%- set visible_columns = get_visible_columns(doc.get(df.fieldname), table_meta, df) -%} -
+
- + {% for tdf in visible_columns %} - {% endfor %} @@ -34,10 +34,10 @@ {% for d in data %} - + {% for tdf in visible_columns %} - + {% endfor %} {% endfor %} @@ -48,15 +48,19 @@ {%- endif -%} {%- endmacro -%} +{% macro fieldmeta(df) -%} +data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" +{%- endmacro %} + {%- macro render_field_with_label(df, doc) -%} -
+
{% if df.fieldtype not in ("Image","HTML") and doc.get(df.fieldname) != None %} {% endif %}
-
+
{% if doc.get(df.fieldname) != None -%} {{ print_value(df, doc) }}{% endif %}
@@ -65,10 +69,10 @@ {%- macro render_text_field(df, doc) -%} {%- if doc.get(df.fieldname) != None -%} -
+
{%- if df.fieldtype in ("Text", "Code") %}{%- endif %} {%- if df.fieldtype=="Code" %} -
{{ doc.get(df.fieldname) }}
+
{{ doc.get(df.fieldname) }}
{% else -%} {{ doc.get_formatted(df.fieldname, parent_doc or doc) }} {% endif -%} @@ -98,7 +102,7 @@ {%- endmacro %} {% macro get_align_class(fieldtype) %} - {%- if fieldtype in ("Int", "Check", "Float", "Currency") -%}{{ "text-right" }} + {%- if fieldtype in ("Int", "Float", "Currency") -%}{{ "text-right" }} {%- else -%}{{ "" }} {%- endif -%} {% endmacro %}
SrSr + {{ _(tdf.label) }}
{{ d.idx }}{{ d.idx }} -
{{ print_value(tdf, d, doc) }}
+
{{ print_value(tdf, d, doc) }}