From 9c17425a0a0886b8efec9d7ef5a61dd36026cdc7 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Fri, 31 Mar 2023 15:23:47 +0530 Subject: [PATCH] File Size append to file list --- smart_service/apis/master_api.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index ad43d4b..a42db67 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -344,6 +344,7 @@ def change_file_ext(): return False return True + def delete_file_ext(): try: frappe.db.sql(''' @@ -352,4 +353,20 @@ def delete_file_ext(): frappe.db.commit() except: return False - return True \ No newline at end of file + return True + + +@frappe.whitelist(methods=['POST']) +def append_size_file(): + try: + data = frappe.db.sql( + """ SELECT * FROM `tabFile` where file_size = 0 and is_folder!=1; """, as_dict=1) + for d in data: + file_path = base_url + d.get("file_url") + file_size = os.path.getsize(file_path) + frappe.db.sql( + f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) + frappe.db.commit() + return True + except: + return False