From 71f829e2ebfe4242a5f147197948ef7881a8b44d Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Mon, 23 Jul 2018 11:27:47 +0530 Subject: [PATCH 01/11] Make start and end date as mandatory (#5843) --- frappe/desk/doctype/calendar_view/calendar_view.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frappe/desk/doctype/calendar_view/calendar_view.json b/frappe/desk/doctype/calendar_view/calendar_view.json index 227aa90f75..da2bdc3e34 100644 --- a/frappe/desk/doctype/calendar_view/calendar_view.json +++ b/frappe/desk/doctype/calendar_view/calendar_view.json @@ -42,6 +42,7 @@ "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { @@ -72,6 +73,7 @@ "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { @@ -99,9 +101,10 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { @@ -129,9 +132,10 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 } ], @@ -145,7 +149,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-11-14 14:14:11.544811", + "modified": "2018-07-20 08:23:23.737254", "modified_by": "Administrator", "module": "Desk", "name": "Calendar View", From a0a23c1ead14036e6d8fa8c0eeff276448cec413 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Mon, 23 Jul 2018 14:38:50 +0530 Subject: [PATCH 02/11] Only calculate total for int, float and currency fieldtypes (#5852) * Only calculate total for int, float and currency * Fix codacy * Update reportview.js --- .../public/js/frappe/views/reports/reportview.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frappe/public/js/frappe/views/reports/reportview.js b/frappe/public/js/frappe/views/reports/reportview.js index 9e4b84bfaf..40cf915bc7 100644 --- a/frappe/public/js/frappe/views/reports/reportview.js +++ b/frappe/public/js/frappe/views/reports/reportview.js @@ -391,7 +391,7 @@ frappe.views.ReportView = frappe.ui.BaseList.extend({ var me = this; var data = this.get_unique_data(this.column_info); - this.set_totals_row(data); + this.set_totals_row(data, this.column_info); // add sr in data $.each(data, function(i, v) { @@ -617,13 +617,23 @@ frappe.views.ReportView = frappe.ui.BaseList.extend({ }); }, - set_totals_row: function(data) { + set_totals_row: function(data, columns) { + const field_map = {}; + const numeric_fieldtypes = ['Int', 'Currency', 'Float']; + columns.forEach(function(row) { + if (row.docfield) { + let r = row.docfield; + if (numeric_fieldtypes.includes(r.fieldtype)) { + field_map[r.fieldname] = [r.fieldtype]; + } + } + }) if(this.add_totals_row) { var totals_row = {_totals_row: 1}; if(data.length) { data.forEach(function(row, ri) { $.each(row, function(key, value) { - if($.isNumeric(value)) { + if (key in field_map) { totals_row[key] = (totals_row[key] || 0) + value; } }); From b2fbb35efa51fd97c174d40820468a7c06734007 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Tue, 24 Jul 2018 16:34:18 +0530 Subject: [PATCH 03/11] Fix comment mentions to avoid html tags (#5865) * Fix comment mentions to avoid html tags * Add a test case --- frappe/core/doctype/user/test_user.py | 2 ++ frappe/core/doctype/user/user.py | 1 + 2 files changed, 3 insertions(+) diff --git a/frappe/core/doctype/user/test_user.py b/frappe/core/doctype/user/test_user.py index 55745f97df..a5b54e7b8d 100644 --- a/frappe/core/doctype/user/test_user.py +++ b/frappe/core/doctype/user/test_user.py @@ -260,6 +260,8 @@ class TestUser(unittest.TestCase): def test_comment_mentions(self): user_name = "@test.comment@example.com" self.assertEqual(extract_mentions(user_name)[0], "test.comment@example.com") + user_name = "@test.comment@test-example.com" + self.assertEqual(extract_mentions(user_name)[0], "test.comment@test-example.com") user_name = "Testing comment, @test-user please check." self.assertEqual(extract_mentions(user_name)[0], "test-user") user_name = "Testing comment, @test.user@example.com please check." diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 4b2de59778..cb85399fb9 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -901,6 +901,7 @@ def notify_admin_access_to_system_manager(login_manager=None): def extract_mentions(txt): """Find all instances of @name in the string. The mentions will be separated by non-word characters or may appear at the start of the string""" + txt = re.sub(r'(<[a-zA-Z\/][^>]*>)', '', txt) return re.findall(r'(?:[^\w\.\-\@]|^)@([\w\.\-\@]*)', txt) From 98a03f9f0a960267ac4c0a41ce07163e66d2fdf8 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 26 Jul 2018 12:39:23 +0530 Subject: [PATCH 04/11] Use "POST" request in ListView (#5870) --- frappe/public/js/frappe/ui/base_list.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/public/js/frappe/ui/base_list.js b/frappe/public/js/frappe/ui/base_list.js index 0d3b1957e8..3a239f5bc0 100644 --- a/frappe/public/js/frappe/ui/base_list.js +++ b/frappe/public/js/frappe/ui/base_list.js @@ -322,7 +322,6 @@ frappe.ui.BaseList = Class.extend({ return frappe.call({ method: this.opts.method || 'frappe.desk.query_builder.runquery', - type: "GET", freeze: this.opts.freeze !== undefined ? this.opts.freeze : true, args: args, callback: function (r) { From 9b7882494667143ea4b2fa5af065d03d712f224e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 26 Jul 2018 12:47:30 +0530 Subject: [PATCH 05/11] [First Cut] Address Info for customer (#5872) --- frappe/core/page/billing_info/__init__.py | 0 .../core/page/billing_info/billing_info.html | 21 ++++ frappe/core/page/billing_info/billing_info.js | 108 ++++++++++++++++++ .../core/page/billing_info/billing_info.json | 22 ++++ frappe/core/page/billing_info/billing_info.py | 37 ++++++ frappe/public/js/frappe/toolbar.js | 1 + 6 files changed, 189 insertions(+) create mode 100644 frappe/core/page/billing_info/__init__.py create mode 100644 frappe/core/page/billing_info/billing_info.html create mode 100644 frappe/core/page/billing_info/billing_info.js create mode 100644 frappe/core/page/billing_info/billing_info.json create mode 100644 frappe/core/page/billing_info/billing_info.py diff --git a/frappe/core/page/billing_info/__init__.py b/frappe/core/page/billing_info/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/core/page/billing_info/billing_info.html b/frappe/core/page/billing_info/billing_info.html new file mode 100644 index 0000000000..c55217ffe0 --- /dev/null +++ b/frappe/core/page/billing_info/billing_info.html @@ -0,0 +1,21 @@ +
+
+

{{ __("Address Details") }}

+
+
+ {% if billing_info.address %} +
You cannot edit your billing info, if they are invalid, please contact support. +
+ +
+
+ Name: {{ billing_info.billing_name }} +

+ Address: + {{ billing_info.address }} +
+ {% else %} + + {% endif %} +
+
diff --git a/frappe/core/page/billing_info/billing_info.js b/frappe/core/page/billing_info/billing_info.js new file mode 100644 index 0000000000..9664963ed1 --- /dev/null +++ b/frappe/core/page/billing_info/billing_info.js @@ -0,0 +1,108 @@ +frappe.pages['billing-info'].on_page_load = function(wrapper) { + var page = frappe.ui.make_app_page({ + parent: wrapper, + title: 'Billing Info', + single_column: true + }); + + frappe.call({ + method: "frappe.core.page.billing_info.billing_info.get_billing_details", + callback: function(r) { + var billing_info = r.message; + + $(frappe.render_template("billing_info", billing_info)).appendTo(page.main); + + $(page.main).find('.btn-primary').on('click', () => { + setup_billing_address($(page.main)) + }); + } + }); + +} + +setup_billing_address = function(page){ + var d = new frappe.ui.Dialog({ + title: __('New Address'), + fields: [ + { + "label": "Adress Title", + "fieldname": "address_title", + "fieldtype": "Data", + "reqd": 1 + }, + { + "label": "Address Type", + "fieldname": "address_type", + "fieldtype": "Data", + "read_only": 1, + "default": "Billing" + }, + { + "label": "Address Line 1", + "fieldname": "address_line1", + "fieldtype": "Data", + "reqd": 1 + }, + { + "label": "Address Line 2", + "fieldname": "address_line2", + "fieldtype": "Data" + }, + { + "fieldname": "cb1", + "fieldtype": "Column Break", + }, + { + "label": "City", + "fieldname": "city", + "fieldtype": "Data", + "reqd": 1 + }, + { + "label": "State", + "fieldname": "state", + "fieldtype": "Data" + }, + { + "label": "Country", + "fieldname": "country", + "fieldtype": "Data", + "reqd": 1 + }, + { + "label": "Pincode", + "fieldname": "pincode", + "fieldtype": "Data" + }, + { + "label": "GST Details", + "fieldname": "gst_details", + "fieldtype": "Section Break", + "depends_on": "eval:doc.country && doc.country.toLowerCase()=='india'" + }, + { + "label": "GSTIN", + "fieldname": "gstin", + "fieldtype": "Data" + } + ], + primary_action: function() { + var data = d.get_values(); + d.hide() + + frappe.call({ + method: "frappe.core.page.billing_info.billing_info.setup_billing_address", + args: { + data: data + }, + freeze: true, + freeze_message: __('Saving Address'), + callback: function(r){ + frappe.ui.toolbar.clear_cache(); + } + }) + }, + }); + + d.show(); +} diff --git a/frappe/core/page/billing_info/billing_info.json b/frappe/core/page/billing_info/billing_info.json new file mode 100644 index 0000000000..f06588c2c2 --- /dev/null +++ b/frappe/core/page/billing_info/billing_info.json @@ -0,0 +1,22 @@ +{ + "content": null, + "creation": "2018-07-25 18:14:53.475842", + "docstatus": 0, + "doctype": "Page", + "idx": 0, + "modified": "2018-07-25 18:14:53.475842", + "modified_by": "Administrator", + "module": "Core", + "name": "billing-info", + "owner": "Administrator", + "page_name": "billing-info", + "roles": [ + { + "role": "System Manager" + } + ], + "script": null, + "standard": "Yes", + "style": null, + "title": "Usage Info" +} \ No newline at end of file diff --git a/frappe/core/page/billing_info/billing_info.py b/frappe/core/page/billing_info/billing_info.py new file mode 100644 index 0000000000..5c9780d4a9 --- /dev/null +++ b/frappe/core/page/billing_info/billing_info.py @@ -0,0 +1,37 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt +from __future__ import unicode_literals + +import frappe +import json +from frappe import _ +from frappe.utils import get_request_session + +@frappe.whitelist() +def get_billing_details(): + s = get_request_session() + data = {"site_name": frappe.local.site} + + try: + res = s.get(frappe.conf.billing_api['get_url'], data=json.dumps(data)) + res.raise_for_status() + + return res.json().get("message") + except Exception: + return {"billing_info": {}} + +@frappe.whitelist() +def setup_billing_address(data): + s = get_request_session() + + data = { + "site_name": frappe.local.site, + "address_details": json.loads(data) + } + + try: + res = s.post(frappe.conf.billing_api['post_url'], data=json.dumps(data)) + res.raise_for_status() + except: + frappe.msgprint(_("Something went wrong while saving the address. Please contact us at support@erpnext.com")) + \ No newline at end of file diff --git a/frappe/public/js/frappe/toolbar.js b/frappe/public/js/frappe/toolbar.js index a466e038bd..efbff10c27 100755 --- a/frappe/public/js/frappe/toolbar.js +++ b/frappe/public/js/frappe/toolbar.js @@ -30,6 +30,7 @@ $(document).on("toolbar_setup", function() { if(limits.space || limits.users || limits.expiry || limits.emails) { help_links = []; help_links.push('
  • ' + frappe._('Usage Info') + '
  • '); + help_links.push('
  • ' + frappe._('Billing') + '
  • '); help_links.push('
  • '); $(help_links.join("\n")).insertBefore($("#toolbar-user").find("li:first")); } From e2b802f0f14090992a1716e1826eb49534869a98 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 26 Jul 2018 12:58:43 +0530 Subject: [PATCH 06/11] Revert "[First Cut] Address Info for customer (#5872)" (#5873) This reverts commit 9b7882494667143ea4b2fa5af065d03d712f224e. --- frappe/core/page/billing_info/__init__.py | 0 .../core/page/billing_info/billing_info.html | 21 ---- frappe/core/page/billing_info/billing_info.js | 108 ------------------ .../core/page/billing_info/billing_info.json | 22 ---- frappe/core/page/billing_info/billing_info.py | 37 ------ frappe/public/js/frappe/toolbar.js | 1 - 6 files changed, 189 deletions(-) delete mode 100644 frappe/core/page/billing_info/__init__.py delete mode 100644 frappe/core/page/billing_info/billing_info.html delete mode 100644 frappe/core/page/billing_info/billing_info.js delete mode 100644 frappe/core/page/billing_info/billing_info.json delete mode 100644 frappe/core/page/billing_info/billing_info.py diff --git a/frappe/core/page/billing_info/__init__.py b/frappe/core/page/billing_info/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/frappe/core/page/billing_info/billing_info.html b/frappe/core/page/billing_info/billing_info.html deleted file mode 100644 index c55217ffe0..0000000000 --- a/frappe/core/page/billing_info/billing_info.html +++ /dev/null @@ -1,21 +0,0 @@ -
    -
    -

    {{ __("Address Details") }}

    -
    -
    - {% if billing_info.address %} -
    You cannot edit your billing info, if they are invalid, please contact support. -
    - -
    -
    - Name: {{ billing_info.billing_name }} -

    - Address: - {{ billing_info.address }} -
    - {% else %} - - {% endif %} -
    -
    diff --git a/frappe/core/page/billing_info/billing_info.js b/frappe/core/page/billing_info/billing_info.js deleted file mode 100644 index 9664963ed1..0000000000 --- a/frappe/core/page/billing_info/billing_info.js +++ /dev/null @@ -1,108 +0,0 @@ -frappe.pages['billing-info'].on_page_load = function(wrapper) { - var page = frappe.ui.make_app_page({ - parent: wrapper, - title: 'Billing Info', - single_column: true - }); - - frappe.call({ - method: "frappe.core.page.billing_info.billing_info.get_billing_details", - callback: function(r) { - var billing_info = r.message; - - $(frappe.render_template("billing_info", billing_info)).appendTo(page.main); - - $(page.main).find('.btn-primary').on('click', () => { - setup_billing_address($(page.main)) - }); - } - }); - -} - -setup_billing_address = function(page){ - var d = new frappe.ui.Dialog({ - title: __('New Address'), - fields: [ - { - "label": "Adress Title", - "fieldname": "address_title", - "fieldtype": "Data", - "reqd": 1 - }, - { - "label": "Address Type", - "fieldname": "address_type", - "fieldtype": "Data", - "read_only": 1, - "default": "Billing" - }, - { - "label": "Address Line 1", - "fieldname": "address_line1", - "fieldtype": "Data", - "reqd": 1 - }, - { - "label": "Address Line 2", - "fieldname": "address_line2", - "fieldtype": "Data" - }, - { - "fieldname": "cb1", - "fieldtype": "Column Break", - }, - { - "label": "City", - "fieldname": "city", - "fieldtype": "Data", - "reqd": 1 - }, - { - "label": "State", - "fieldname": "state", - "fieldtype": "Data" - }, - { - "label": "Country", - "fieldname": "country", - "fieldtype": "Data", - "reqd": 1 - }, - { - "label": "Pincode", - "fieldname": "pincode", - "fieldtype": "Data" - }, - { - "label": "GST Details", - "fieldname": "gst_details", - "fieldtype": "Section Break", - "depends_on": "eval:doc.country && doc.country.toLowerCase()=='india'" - }, - { - "label": "GSTIN", - "fieldname": "gstin", - "fieldtype": "Data" - } - ], - primary_action: function() { - var data = d.get_values(); - d.hide() - - frappe.call({ - method: "frappe.core.page.billing_info.billing_info.setup_billing_address", - args: { - data: data - }, - freeze: true, - freeze_message: __('Saving Address'), - callback: function(r){ - frappe.ui.toolbar.clear_cache(); - } - }) - }, - }); - - d.show(); -} diff --git a/frappe/core/page/billing_info/billing_info.json b/frappe/core/page/billing_info/billing_info.json deleted file mode 100644 index f06588c2c2..0000000000 --- a/frappe/core/page/billing_info/billing_info.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "content": null, - "creation": "2018-07-25 18:14:53.475842", - "docstatus": 0, - "doctype": "Page", - "idx": 0, - "modified": "2018-07-25 18:14:53.475842", - "modified_by": "Administrator", - "module": "Core", - "name": "billing-info", - "owner": "Administrator", - "page_name": "billing-info", - "roles": [ - { - "role": "System Manager" - } - ], - "script": null, - "standard": "Yes", - "style": null, - "title": "Usage Info" -} \ No newline at end of file diff --git a/frappe/core/page/billing_info/billing_info.py b/frappe/core/page/billing_info/billing_info.py deleted file mode 100644 index 5c9780d4a9..0000000000 --- a/frappe/core/page/billing_info/billing_info.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# MIT License. See license.txt -from __future__ import unicode_literals - -import frappe -import json -from frappe import _ -from frappe.utils import get_request_session - -@frappe.whitelist() -def get_billing_details(): - s = get_request_session() - data = {"site_name": frappe.local.site} - - try: - res = s.get(frappe.conf.billing_api['get_url'], data=json.dumps(data)) - res.raise_for_status() - - return res.json().get("message") - except Exception: - return {"billing_info": {}} - -@frappe.whitelist() -def setup_billing_address(data): - s = get_request_session() - - data = { - "site_name": frappe.local.site, - "address_details": json.loads(data) - } - - try: - res = s.post(frappe.conf.billing_api['post_url'], data=json.dumps(data)) - res.raise_for_status() - except: - frappe.msgprint(_("Something went wrong while saving the address. Please contact us at support@erpnext.com")) - \ No newline at end of file diff --git a/frappe/public/js/frappe/toolbar.js b/frappe/public/js/frappe/toolbar.js index efbff10c27..a466e038bd 100755 --- a/frappe/public/js/frappe/toolbar.js +++ b/frappe/public/js/frappe/toolbar.js @@ -30,7 +30,6 @@ $(document).on("toolbar_setup", function() { if(limits.space || limits.users || limits.expiry || limits.emails) { help_links = []; help_links.push('
  • ' + frappe._('Usage Info') + '
  • '); - help_links.push('
  • ' + frappe._('Billing') + '
  • '); help_links.push('
  • '); $(help_links.join("\n")).insertBefore($("#toolbar-user").find("li:first")); } From 5ddcf40a11947e2347a803230aafcb14dd8143bd Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Fri, 27 Jul 2018 11:55:48 +0530 Subject: [PATCH 07/11] [python3] let PdfFileReader handle file opening (#5878) In Python 3, file() is deprecated. PdfFileReader can internally handle file opening and closing, so file() no longer necessary. See description of stream parameter here: https://pythonhosted.org/PyPDF2/PdfFileReader.html#PyPDF2.PdfFileReader Alternatively, open() can be used. --- frappe/utils/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/utils/pdf.py b/frappe/utils/pdf.py index 57c4051be6..fd98441517 100644 --- a/frappe/utils/pdf.py +++ b/frappe/utils/pdf.py @@ -16,7 +16,7 @@ def get_pdf(html, options=None, output = None): try: pdfkit.from_string(html, fname, options=options or {}) if output: - append_pdf(PdfFileReader(file(fname,"rb")),output) + append_pdf(PdfFileReader(fname),output) else: with open(fname, "rb") as fileobj: filedata = fileobj.read() From 92f288bc2f432096063a6b0e3c5176464519a6df Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Fri, 27 Jul 2018 11:55:58 +0530 Subject: [PATCH 08/11] added 2 fucntions to frappe.utils (#5877) * added 2 fucntions to frappe.utils - get_db_count: to get the db count of any DocType - call: a wrapper for frappe.call * Update __init__.py --- frappe/utils/__init__.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index d807c018f1..390cedffb4 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -548,3 +548,37 @@ def get_site_info(): # dumps -> loads to prevent datatype conflicts return json.loads(frappe.as_json(site_info)) + +def get_db_count(*args): + """ + Pass a doctype or a series of doctypes to get the count of docs in them + Parameters: + *args: Variable length argument list of doctype names whose doc count you need + + Returns: + dict: A dict with the count values. + + Example: + via terminal: + bench --site erpnext.local execute frappe.utils.get_db_count --args "['DocType', 'Communication']" + """ + db_count = {} + for doctype in args: + db_count[doctype] = frappe.db.count(doctype) + + return json.loads(frappe.as_json(db_count)) + +def call(fn, *args, **kwargs): + """ + Pass a doctype or a series of doctypes to get the count of docs in them + Parameters: + fn: frappe function to be called + + Returns: + based on the function you call: output of the function you call + + Example: + via terminal: + bench --site erpnext.local execute frappe.utils.call --args '''["frappe.get_all", "Activity Log"]''' --kwargs '''{"fields": ["user", "creation", "full_name"], "filters":{"Operation": "Login", "Status": "Success"}, "limit": "10"}''' + """ + return json.loads(frappe.as_json(frappe.call(fn, *args, **kwargs))) From 389739b5bb2269ea4ae34602a8b5251fa9e093a7 Mon Sep 17 00:00:00 2001 From: Zarrar Date: Mon, 30 Jul 2018 12:01:46 +0530 Subject: [PATCH 09/11] Bold email mentions in comment section (#5879) --- frappe/public/js/frappe/form/footer/timeline.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/form/footer/timeline.js b/frappe/public/js/frappe/form/footer/timeline.js index 177d168fb5..7c760b80a3 100644 --- a/frappe/public/js/frappe/form/footer/timeline.js +++ b/frappe/public/js/frappe/form/footer/timeline.js @@ -310,9 +310,9 @@ frappe.ui.form.Timeline = Class.extend({ // bold @mentions if(c.comment_type==="Comment" && // avoid adding tag a 2nd time - !c.content_html.match(/(^|\W)(@\w+)<\/b>/) + !c.content_html.match(/(^|\W)(@[^\s]+)<\/b>/) ) { - c.content_html = c.content_html.replace(/(^|\W)(@\w+)/g, "$1$2"); + c.content_html = c.content_html.replace(/(^|\W)(@[^\s]+)/g, "$1$2"); } if (this.is_communication_or_comment(c)) { From 4c20d1f68f8843b70364c3d26a4d8175d2e4eb4d Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Mon, 30 Jul 2018 14:32:33 +0530 Subject: [PATCH 10/11] using regex instead of soup to parse pdf page margins (#5883) * using regex instead of soup to parse pdf page margins * Fix codacy --- frappe/utils/pdf.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frappe/utils/pdf.py b/frappe/utils/pdf.py index fd98441517..dd22066c55 100644 --- a/frappe/utils/pdf.py +++ b/frappe/utils/pdf.py @@ -7,6 +7,7 @@ from frappe.utils import scrub_urls from frappe import _ from bs4 import BeautifulSoup from PyPDF2 import PdfFileWriter, PdfFileReader +import re def get_pdf(html, options=None, output = None): html = scrub_urls(html) @@ -88,12 +89,13 @@ def read_options_from_html(html): toggle_visible_pdf(soup) - # extract pdfkit options from html - for html_id in ("margin-top", "margin-bottom", "margin-left", "margin-right", "page-size"): + # use regex instead of soup-parser + for attr in ("margin-top", "margin-bottom", "margin-left", "margin-right", "page-size"): try: - tag = soup.find(id=html_id) - if tag and tag.contents: - options[html_id] = tag.contents + pattern = re.compile(r"(\.print-format)([\S|\s][^}]*?)(" + str(attr) + r":)(.+)(mm;)") + match = pattern.findall(html) + if match: + options[attr] = str(match[-1][3]).strip() except: pass From cdfba6fd4c4c13e920abbb2a48291cac41d30c0f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 31 Jul 2018 13:10:42 +0600 Subject: [PATCH 11/11] bumped to version 10.1.43 --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 8ab079ab58..af64977665 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -14,7 +14,7 @@ import os, sys, importlib, inspect, json from .exceptions import * from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template -__version__ = '10.1.42' +__version__ = '10.1.43' __title__ = "Frappe Framework" local = Local()