diff --git a/frappe/templates/print_format/macros.html b/frappe/templates/print_format/macros.html index 6eae98351d..ace992e88d 100644 --- a/frappe/templates/print_format/macros.html +++ b/frappe/templates/print_format/macros.html @@ -1,4 +1,5 @@ {% macro render_field(df, doc) %} +{%- set value = doc.get(df.fieldname) -%} {% include ['templates/print_format/macros/' + df.renderer + '.html', 'templates/print_format/macros/Data.html'] ignore missing %} {% endmacro %} diff --git a/frappe/templates/print_format/macros/Attach.html b/frappe/templates/print_format/macros/Attach.html new file mode 100644 index 0000000000..523d9e057a --- /dev/null +++ b/frappe/templates/print_format/macros/Attach.html @@ -0,0 +1,7 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+ {{ value.rsplit('/', 1)[1] }} +
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/AttachImage.html b/frappe/templates/print_format/macros/AttachImage.html new file mode 100644 index 0000000000..796662f67a --- /dev/null +++ b/frappe/templates/print_format/macros/AttachImage.html @@ -0,0 +1,7 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+ {{ df.label }} +
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/Check.html b/frappe/templates/print_format/macros/Check.html new file mode 100644 index 0000000000..fbc43608a5 --- /dev/null +++ b/frappe/templates/print_format/macros/Check.html @@ -0,0 +1,9 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+ + + +
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/Code.html b/frappe/templates/print_format/macros/Code.html new file mode 100644 index 0000000000..e83457808a --- /dev/null +++ b/frappe/templates/print_format/macros/Code.html @@ -0,0 +1,7 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+
{{ value }}
+
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/Color.html b/frappe/templates/print_format/macros/Color.html new file mode 100644 index 0000000000..ef7a2226c6 --- /dev/null +++ b/frappe/templates/print_format/macros/Color.html @@ -0,0 +1,8 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+
+ {{ value }} +
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/Data.html b/frappe/templates/print_format/macros/Data.html index 2fa0e1484b..722c42ce1a 100644 --- a/frappe/templates/print_format/macros/Data.html +++ b/frappe/templates/print_format/macros/Data.html @@ -1,21 +1,10 @@ -{% if doc.get(df.fieldname) %} -{%- if df.section.field_orientation == 'left-right' -%} -
-
- {{ df.label }} -
-
- {{ doc.get_formatted(df.fieldname) }} -
+{% if value %} +
+ {%- block label -%} +
{{ df.label }}
+ {%- endblock -%} + {%- block value -%} +
{{ doc.get_formatted(df.fieldname) }}
+ {%- endblock -%}
-{%- else -%} -
-
- {{ df.label }} -
-
- {{ doc.get_formatted(df.fieldname) }} -
-
-{%- endif -%} {% endif %} diff --git a/frappe/templates/print_format/macros/HTML.html b/frappe/templates/print_format/macros/HTML.html index 51f02808d9..6bd3659902 100644 --- a/frappe/templates/print_format/macros/HTML.html +++ b/frappe/templates/print_format/macros/HTML.html @@ -1,3 +1,3 @@ -
+
{{ frappe.render_template(df.html, {'doc': doc}) }}
diff --git a/frappe/templates/print_format/macros/Markdown.html b/frappe/templates/print_format/macros/Markdown.html index 7a4b16a3a8..b692283fa0 100644 --- a/frappe/templates/print_format/macros/Markdown.html +++ b/frappe/templates/print_format/macros/Markdown.html @@ -1,3 +1,9 @@ -
+{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
{{ frappe.utils.md_to_html(doc.get(df.fieldname)) }}
+{%- endblock -%} + + diff --git a/frappe/templates/print_format/macros/Rating.html b/frappe/templates/print_format/macros/Rating.html new file mode 100644 index 0000000000..2e001fb58f --- /dev/null +++ b/frappe/templates/print_format/macros/Rating.html @@ -0,0 +1,22 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{% macro star(is_active=false) %} + + {%- set color = '#f6c35e' if is_active else '#dce0e3' -%} + + +{% endmacro %} + +{%- block value -%} +
+ {%- for i in range(value) -%} + {{ star(true) }} + {%- endfor -%} + {%- for i in range(5 - value) -%} + {{ star() }} + {%- endfor -%} +
+{%- endblock -%} diff --git a/frappe/templates/print_format/macros/Signature.html b/frappe/templates/print_format/macros/Signature.html new file mode 100644 index 0000000000..128ff2a927 --- /dev/null +++ b/frappe/templates/print_format/macros/Signature.html @@ -0,0 +1,7 @@ +{% extends "templates/print_format/macros/Data.html" %} + +{%- block value -%} +
+ {{ df.label }} +
+{%- endblock -%} diff --git a/frappe/templates/print_format/print_format.css b/frappe/templates/print_format/print_format.css index 41e68e1022..480cd19439 100644 --- a/frappe/templates/print_format/print_format.css +++ b/frappe/templates/print_format/print_format.css @@ -76,6 +76,18 @@ body { font-weight: bold; } +.field.left-right { + display: flex; +} + +.field.left-right .label { + width: 50%; +} + +.field.left-right .value { + width: 50%; +} + .child-table [data-fieldtype="Currency"] { text-align: right; } @@ -93,3 +105,27 @@ body { border-bottom-style: solid; border-bottom-color: var(--gray-300); } + +.field[data-fieldtype="Rating"] .rating-star { + width: 1.5rem; +} + +.field[data-fieldtype="Long Text"] .value, .field[data-fieldtype="Text"] .value { + white-space: pre-line; +} + +.field[data-fieldtype="Color"] .value { + display: flex; + align-items: center; +} + +.field[data-fieldtype="Color"] .color-square { + width: 1rem; + height: 1rem; + margin-right: 0.3rem; + border-radius: var(--border-radius); +} + +.field[data-fieldtype="Check"] #icon-tick { + width: 1rem; +} diff --git a/frappe/utils/weasyprint.py b/frappe/utils/weasyprint.py index e66747e48a..006bab2dd0 100644 --- a/frappe/utils/weasyprint.py +++ b/frappe/utils/weasyprint.py @@ -204,16 +204,13 @@ class PrintFormatGenerator: return layout def set_field_renderers(self, layout): - renderers = { - "HTML Editor": "HTML", - "Markdown Editor": "Markdown", - "Field Template": "FieldTemplate", - } + renderers = {"HTML Editor": "HTML", "Markdown Editor": "Markdown"} for section in layout["sections"]: for column in section["columns"]: for df in column["fields"]: fieldtype = df["fieldtype"] - df["renderer"] = renderers.get(fieldtype) or fieldtype + renderer_name = fieldtype.replace(" ", "") + df["renderer"] = renderers.get(fieldtype) or renderer_name df["section"] = section return layout