From 96f7c6809395c71595386a6a6733d7d87edea9ed Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Tue, 18 Apr 2023 12:05:37 +0530 Subject: [PATCH] File ext validation --- smart_service/apis/master_api.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index ad3a70e..635c47a 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -390,13 +390,15 @@ def asset_to_files_path(): def change_file_dir(): data = frappe.db.sql(''' - select name,file from tabProcedure_Details where content_type = 'File';''', as_dict=1) + select name,file from tabProcedure_Details where content_type = 'File' where file_url = '/files/Driver Seat Back Rest Foam.jpg' ;''', as_dict=1) for d in data: + frappe.log_error("File data :", str(file_name)) + path = os.path.join(base_url, d['file']) isExist = os.path.exists(path) + frappe.log_error("Path exists :", str(isExist)) if not isExist: - frappe.log_error("Invalid file:", str(path)) ext = path[-3:] path = path[:-3] extension = '' @@ -405,13 +407,16 @@ def change_file_dir(): if ext == 'jpg': extension = 'png' + path = path[:-3] + extension + frappe.log_error("New path:", str(path)) if os.path.exists(path): - file_name = d[:-3]+ extension + file_name = d[:-3] + extension + frappe.log_error("New file :", str(file_name)) - frappe.db.sql(f''' - update tabProcedure_Details set file = '{d[:-3]+ ext}' where content_type = 'File' and name = '{d['name']}'; - ''') + # frappe.db.sql(f''' + # update tabProcedure_Details set file = '{d[:-3]+ ext}' where content_type = 'File' and name = '{d['name']}'; + # ''') # frappe.db.commit() return data