Browse Source

File ext file path validation

master
venkataakhil 2 years ago
parent
commit
277a2408bb
  1. 45
      smart_service/apis/master_api.py

45
smart_service/apis/master_api.py

@ -392,15 +392,39 @@ def change_file_dir():
data = frappe.db.sql('''
select name,file from tabProcedure_Details where content_type = 'File' and file = '/files/Driver Seat Back Rest Foam.jpg' ;''', as_dict=1)
# for d in data:
# frappe.log_error("File data :", str(d))
# path = os.path.join(base_url, d['file'])
# isExist = os.path.exists(path)
# frappe.log_error("Path exists :", str(isExist))
# if not isExist:
# ext = path[-3:]
# path = path[:-3]
# extension = ''
# if ext == 'png':
# extension = 'jpg'
# 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
# frappe.log_error("New file :", str(file_name))
for d in data:
frappe.log_error("File data :", str(d))
path = os.path.join(base_url, d['file'])
isExist = os.path.exists(path)
path = d['file']
isExist = os.path.exists(os.path.join(base_url, path))
frappe.log_error("Path exists :", str(isExist))
if not isExist:
ext = path[-3:]
path = path[:-3]
extension = ''
if ext == 'png':
extension = 'jpg'
@ -408,16 +432,17 @@ 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
new_full_path = path + extension
frappe.log_error("New path:", str(new_full_path))
if os.path.exists(os.path.join(base_url,new_full_path)):
frappe.log_error("New file :", str(file_name))
frappe.log_error("final", str('ext changed File exists in local'))
# frappe.db.sql(f'''
# update tabProcedure_Details set file = '{d[:-3]+ ext}' where content_type = 'File' and name = '{d['name']}';
# ''')
# update tabProcedure_Details set file = '{new_full_path}' where content_type = 'File' and name = '{d['name']}';
# ''')
# frappe.db.commit()
if data:
return data
else:

Loading…
Cancel
Save