diff --git a/frappe/__init__.py b/frappe/__init__.py index c8245b0bf0..9cc83d63a4 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -137,10 +137,10 @@ lang = local("lang") if typing.TYPE_CHECKING: from frappe.database.mariadb.database import MariaDBDatabase from frappe.database.postgres.database import PostgresDatabase - from pypika import Query + from frappe.query_builder.builder import MariaDB, Postgres db: typing.Union[MariaDBDatabase, PostgresDatabase] - qb: Query + qb: typing.Union[MariaDB, Postgres] # end: static analysis hack diff --git a/frappe/core/doctype/access_log/access_log.py b/frappe/core/doctype/access_log/access_log.py index f631353d56..48c12fd93f 100644 --- a/frappe/core/doctype/access_log/access_log.py +++ b/frappe/core/doctype/access_log/access_log.py @@ -1,6 +1,7 @@ # Copyright (c) 2021, Frappe Technologies and contributors # License: MIT. See LICENSE import frappe +from frappe.utils import cstr from tenacity import retry, retry_if_exception_type, stop_after_attempt from frappe.model.document import Document @@ -24,25 +25,21 @@ def make_access_log( page=None, columns=None, ): - user = frappe.session.user in_request = frappe.request and frappe.request.method == "GET" - doc = frappe.get_doc( - { - "doctype": "Access Log", - "user": user, - "export_from": doctype, - "reference_document": document, - "file_type": file_type, - "report_name": report_name, - "page": page, - "method": method, - "filters": frappe.utils.cstr(filters) if filters else None, - "columns": columns, - } - ) - doc.insert(ignore_permissions=True) + frappe.get_doc({ + "doctype": "Access Log", + "user": user, + "export_from": doctype, + "reference_document": document, + "file_type": file_type, + "report_name": report_name, + "page": page, + "method": method, + "filters": cstr(filters) or None, + "columns": columns, + }).db_insert() # `frappe.db.commit` added because insert doesnt `commit` when called in GET requests like `printview` # dont commit in test mode diff --git a/frappe/public/js/frappe/form/controls/data.js b/frappe/public/js/frappe/form/controls/data.js index 864a0562ef..803c2cf070 100644 --- a/frappe/public/js/frappe/form/controls/data.js +++ b/frappe/public/js/frappe/form/controls/data.js @@ -15,11 +15,6 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp .addClass("input-with-feedback form-control") .prependTo(this.input_area); - if (in_list(['Data', 'Link', 'Dynamic Link', 'Password', 'Select', 'Read Only', 'Attach', 'Attach Image'], - this.df.fieldtype)) { - this.$input.attr("maxlength", this.df.length || 140); - } - this.$input.on('paste', (e) => { let pasted_data = frappe.utils.get_clipboard_data(e); let maxlength = this.$input.attr('maxlength'); @@ -199,6 +194,13 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp } } set_input_attributes() { + if (in_list( + ['Data', 'Link', 'Dynamic Link', 'Password', 'Select', 'Read Only'], + this.df.fieldtype + )) { + this.$input.attr("maxlength", this.df.length || 140); + } + this.$input .attr("data-fieldtype", this.df.fieldtype) .attr("data-fieldname", this.df.fieldname) diff --git a/frappe/public/js/frappe/form/footer/footer.js b/frappe/public/js/frappe/form/footer/footer.js index d6dfc227f0..3c89a86fee 100644 --- a/frappe/public/js/frappe/form/footer/footer.js +++ b/frappe/public/js/frappe/form/footer/footer.js @@ -30,7 +30,7 @@ frappe.ui.form.Footer = class FormFooter { fieldname: 'comment' }, on_submit: (comment) => { - if (strip_html(comment).trim() != "") { + if (strip_html(comment).trim() != "" || comment.includes('img')) { this.frm.comment_box.disable(); frappe.xcall("frappe.desk.form.utils.add_comment", { reference_doctype: this.frm.doctype, diff --git a/frappe/public/scss/website.bundle.scss b/frappe/public/scss/website.bundle.scss index 06ec73c386..bcbb6f3c6a 100644 --- a/frappe/public/scss/website.bundle.scss +++ b/frappe/public/scss/website.bundle.scss @@ -1 +1 @@ -@import './website/index'; +@import './website/index'; \ No newline at end of file diff --git a/frappe/public/scss/website/page_builder.scss b/frappe/public/scss/website/page_builder.scss index 252ad1bf9f..e7e2f8b242 100644 --- a/frappe/public/scss/website/page_builder.scss +++ b/frappe/public/scss/website/page_builder.scss @@ -145,11 +145,6 @@ .section-with-cards .card { @include transition(); - border: none; - - .card-body { - padding: 0 1.5rem 2rem 0; - } &:hover { border-color: $gray-500; diff --git a/frappe/tests/test_website.py b/frappe/tests/test_website.py index 25aa7b31ce..992d876243 100644 --- a/frappe/tests/test_website.py +++ b/frappe/tests/test_website.py @@ -10,7 +10,7 @@ class TestWebsite(unittest.TestCase): frappe.set_user('Guest') def tearDown(self): - frappe.db.value_cache = {} + frappe.db.delete('Access Log') frappe.set_user('Administrator') def test_home_page(self): diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 473321339a..6e0fb44c4b 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -5,6 +5,7 @@ from typing import Optional import frappe import operator import json +import base64 import re, datetime, math, time from code import compile_command from urllib.parse import quote, urljoin @@ -1013,7 +1014,6 @@ def get_thumbnail_base64_for_image(src): return cache().hget('thumbnail_base64', src, generator=_get_base64) def image_to_base64(image, extn): - import base64 from io import BytesIO buffered = BytesIO() @@ -1023,6 +1023,16 @@ def image_to_base64(image, extn): img_str = base64.b64encode(buffered.getvalue()) return img_str +def pdf_to_base64(filename): + from frappe.utils.file_manager import get_file_path + file_path = get_file_path(filename) + if not file_path: + return + + with open(file_path, 'rb') as pdf_file: + base64_string = base64.b64encode(pdf_file.read()) + + return base64_string # from Jinja2 code _striptags_re = re.compile(r'(|<[^>]*>)') diff --git a/frappe/utils/safe_exec.py b/frappe/utils/safe_exec.py index 8f6b33a838..4bc4f3e3be 100644 --- a/frappe/utils/safe_exec.py +++ b/frappe/utils/safe_exec.py @@ -327,6 +327,7 @@ VALID_UTILS = ( "is_image", "get_thumbnail_base64_for_image", "image_to_base64", +"pdf_to_base64", "strip_html", "escape_html", "pretty_date",