fix: Get file name from path (#12437)
* fix: get file name from path * Update frappe/integrations/doctype/dropbox_settings/dropbox_settings.py Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> * fix: upload only files which have file url * fix: patch to fix files name and url * fix: fixing patch * refact: patch refactor * fix: missing : * fix: renamed variables * fix: refactoring patch * fix: update file exists function * fix: added patch path in patch.txt * fix: added try except * fix: Use set_value instead of set_values * style: Fix formatting Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
This commit is contained in:
parent
856e9adf38
commit
a342ca2386
3 changed files with 36 additions and 6 deletions
|
|
@ -131,12 +131,10 @@ def upload_from_folder(path, is_private, dropbox_folder, dropbox_client, did_not
|
|||
|
||||
for f in frappe.get_all("File", filters={"is_folder": 0, "is_private": is_private,
|
||||
"uploaded_to_dropbox": 0}, fields=['file_url', 'name', 'file_name']):
|
||||
if is_private:
|
||||
filename = f.file_url.replace('/private/files/', '')
|
||||
else:
|
||||
if not f.file_url:
|
||||
f.file_url = '/files/' + f.file_name;
|
||||
filename = f.file_url.replace('/files/', '')
|
||||
if not f.file_url:
|
||||
continue
|
||||
filename = f.file_url.rsplit('/', 1)[-1]
|
||||
|
||||
filepath = os.path.join(path, filename)
|
||||
|
||||
if filename in ignore_list:
|
||||
|
|
|
|||
|
|
@ -332,3 +332,4 @@ frappe.patches.v13_0.rename_desk_page_to_workspace # 02.02.2021
|
|||
frappe.patches.v13_0.delete_package_publish_tool
|
||||
frappe.patches.v13_0.rename_list_view_setting_to_list_view_settings
|
||||
frappe.patches.v13_0.remove_twilio_settings
|
||||
frappe.patches.v12_0.rename_uploaded_files_with_proper_name
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import frappe
|
||||
import os
|
||||
|
||||
def execute():
|
||||
file_names_with_url = frappe.get_all("File", filters={
|
||||
"is_folder": 0,
|
||||
"file_name": ["like", "%/%"]
|
||||
}, fields=['name', 'file_name', 'file_url'])
|
||||
|
||||
for f in file_names_with_url:
|
||||
filename = f.file_name.rsplit('/', 1)[-1]
|
||||
|
||||
if not f.file_url:
|
||||
f.file_url = f.file_name
|
||||
|
||||
try:
|
||||
if not file_exists(f.file_url):
|
||||
continue
|
||||
frappe.db.set_value('File', f.name, {
|
||||
"file_name": filename,
|
||||
"file_url": f.file_url
|
||||
}, update_modified=False)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
def file_exists(file_path):
|
||||
file_path = frappe.utils.get_files_path(
|
||||
file_path.rsplit('/', 1)[-1],
|
||||
is_private=file_path.startswith('/private')
|
||||
)
|
||||
return os.path.exists(file_path)
|
||||
Loading…
Add table
Reference in a new issue