From f4bd62c010692bed9a61c245412f44b765697dff Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 15 Sep 2021 18:50:41 +0530 Subject: [PATCH] feat: More features - Letterhead editing - Edit Header and Footer - Margin Text - PrintFormatGenerator class handles generation of HTML and PDF and repeating of Header/Footer - Simplify /printpreview - Separate renderer files for each fieldtype --- frappe/client.py | 6 + .../doctype/print_format/print_format.py | 8 +- .../js/print_format_builder/HTMLEditor.vue | 61 ++++ .../print_format_builder/LetterHeadEditor.vue | 108 +++++++ .../js/print_format_builder/MarginText.vue | 114 +++++++ .../js/print_format_builder/Preview.vue | 3 + .../js/print_format_builder/PrintFormat.vue | 29 +- .../PrintFormatControls.vue | 1 + .../public/js/print_format_builder/store.js | 22 +- frappe/templates/print_format/macros.html | 57 +--- .../templates/print_format/macros/Data.html | 10 + .../templates/print_format/macros/HTML.html | 3 + .../print_format/macros/Markdown.html | 3 + .../templates/print_format/macros/Table.html | 30 ++ .../templates/print_format/print_footer.html | 24 ++ .../templates/print_format/print_format.css | 27 +- .../templates/print_format/print_format.html | 2 + .../print_format/print_format_font.css | 9 + .../templates/print_format/print_header.html | 24 ++ frappe/utils/weasyprint.py | 286 ++++++++++-------- frappe/www/printpreview.html | 11 +- frappe/www/printpreview.py | 15 - 22 files changed, 637 insertions(+), 216 deletions(-) create mode 100644 frappe/public/js/print_format_builder/HTMLEditor.vue create mode 100644 frappe/public/js/print_format_builder/LetterHeadEditor.vue create mode 100644 frappe/public/js/print_format_builder/MarginText.vue create mode 100644 frappe/templates/print_format/macros/Data.html create mode 100644 frappe/templates/print_format/macros/HTML.html create mode 100644 frappe/templates/print_format/macros/Markdown.html create mode 100644 frappe/templates/print_format/macros/Table.html create mode 100644 frappe/templates/print_format/print_footer.html create mode 100644 frappe/templates/print_format/print_format_font.css create mode 100644 frappe/templates/print_format/print_header.html delete mode 100644 frappe/www/printpreview.py diff --git a/frappe/client.py b/frappe/client.py index 21d10e8271..842e5cf199 100644 --- a/frappe/client.py +++ b/frappe/client.py @@ -258,6 +258,12 @@ def set_default(key, value, parent=None): frappe.db.set_default(key, value, parent or frappe.session.user) frappe.clear_cache(user=frappe.session.user) +@frappe.whitelist() +def get_default(key, parent=None): + """set a user default value""" + return frappe.db.get_default(key, parent) + + @frappe.whitelist(methods=['POST', 'PUT']) def make_width_property_setter(doc): '''Set width Property Setter diff --git a/frappe/printing/doctype/print_format/print_format.py b/frappe/printing/doctype/print_format/print_format.py index 2049c4105c..867e36997d 100644 --- a/frappe/printing/doctype/print_format/print_format.py +++ b/frappe/printing/doctype/print_format/print_format.py @@ -7,10 +7,16 @@ import frappe.utils import json from frappe import _ from frappe.utils.jinja import validate_template - +from frappe.utils.weasyprint import get_html, download_pdf from frappe.model.document import Document class PrintFormat(Document): + def get_html(self, docname, letterhead=None): + return get_html(self.doc_type, docname, self.name, letterhead) + + def download_pdf(self, docname, letterhead=None): + return download_pdf(self.doc_type, docname, self.name, letterhead) + def validate(self): if (self.standard=="Yes" and not frappe.local.conf.get("developer_mode") diff --git a/frappe/public/js/print_format_builder/HTMLEditor.vue b/frappe/public/js/print_format_builder/HTMLEditor.vue new file mode 100644 index 0000000000..495964f950 --- /dev/null +++ b/frappe/public/js/print_format_builder/HTMLEditor.vue @@ -0,0 +1,61 @@ + + + diff --git a/frappe/public/js/print_format_builder/LetterHeadEditor.vue b/frappe/public/js/print_format_builder/LetterHeadEditor.vue new file mode 100644 index 0000000000..d958a6e67a --- /dev/null +++ b/frappe/public/js/print_format_builder/LetterHeadEditor.vue @@ -0,0 +1,108 @@ + + + diff --git a/frappe/public/js/print_format_builder/MarginText.vue b/frappe/public/js/print_format_builder/MarginText.vue new file mode 100644 index 0000000000..85229d2d42 --- /dev/null +++ b/frappe/public/js/print_format_builder/MarginText.vue @@ -0,0 +1,114 @@ + + + diff --git a/frappe/public/js/print_format_builder/Preview.vue b/frappe/public/js/print_format_builder/Preview.vue index 1ce89a87aa..1d795f27d7 100644 --- a/frappe/public/js/print_format_builder/Preview.vue +++ b/frappe/public/js/print_format_builder/Preview.vue @@ -97,6 +97,9 @@ export default { params.append("doctype", this.doctype); params.append("name", this.docname); params.append("print_format", this.print_format.name); + if (this.$store.letterhead) { + params.append("letterhead", this.$store.letterhead.name); + } let url = this.type == "PDF" ? `/api/method/frappe.utils.weasyprint.download_pdf` diff --git a/frappe/public/js/print_format_builder/PrintFormat.vue b/frappe/public/js/print_format_builder/PrintFormat.vue index f0f7f713ea..74cfb84133 100644 --- a/frappe/public/js/print_format_builder/PrintFormat.vue +++ b/frappe/public/js/print_format_builder/PrintFormat.vue @@ -1,6 +1,20 @@