From 0b6acd1899335d82061c1d475a4193ca657dd38d Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Thu, 10 Jun 2021 17:55:44 +1000 Subject: [PATCH] changed to consistently use restore instead of awful undelete --- files.py | 8 ++++---- pa_job_manager.py | 20 ++++++++++---------- templates/files.html | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/files.py b/files.py index a93a91f..7b19216 100644 --- a/files.py +++ b/files.py @@ -345,16 +345,16 @@ def rm_dups(): return render_template("base.html") -@app.route("/undelete_files", methods=["POST"]) -def undelete_files(): +@app.route("/restore_files", methods=["POST"]) +def restore_files(): jex=[] for el in request.form: print( f"{el}={request.form[el]}" ) jex.append( JobExtra( name=f"{el}", value=request.form[el] ) ) - job=NewJob( "undelete_files", 0, None, jex ) + job=NewJob( "restore_files", 0, None, jex ) st.SetAlert("success") - st.SetMessage( f"Created Job #{job.id} to undelete selected file(s)") + st.SetMessage( f"Created Job #{job.id} to restore selected file(s)") return render_template("base.html") @app.route("/delete_files", methods=["POST"]) diff --git a/pa_job_manager.py b/pa_job_manager.py index 4a0ab7a..9ee7462 100644 --- a/pa_job_manager.py +++ b/pa_job_manager.py @@ -399,8 +399,8 @@ def RunJob(job): RemoveDups(job) elif job.name == "delete_files": JobDeleteFiles(job) - elif job.name == "undelete_files": - JobUnDeleteFiles(job) + elif job.name == "restore_files": + JobRestoreFiles(job) elif job.name == "processai": JobProcessAI(job) else: @@ -608,10 +608,10 @@ def RemoveFileFromFS( del_me ): print( f"ERROR: Failed to remove file from filesystem - which={src}, err: {e}") return -# Function that undeletes a file that was deleted (moved into the Bin) +# Function that restores a file that was deleted (moved into the Bin) # it moves file on the filesystem back to its original path and then changes the database path from the Bin path # to the original import or storage path and appropriate dir -def UnDeleteFile(job,restore_me): +def RestoreFile(job,restore_me): try: # rel_path for a file in the Bin, is like 'Import/images_to_process/1111', so just prepend static/ dst_dir='static/' + restore_me.in_dir.rel_path + '/' @@ -620,7 +620,7 @@ def UnDeleteFile(job,restore_me): dst=dst_dir + '/' + restore_me.name os.replace( src, dst ) except Exception as e: - print( f"ERROR: Failed to undelete (mv) file on filesystem - which={src} to {dst}, err: {e}") + print( f"ERROR: Failed to restores (mv) file on filesystem - which={src} to {dst}, err: {e}") # need these for AddDir calls below to work orig_file_details = session.query(DelFile).get(restore_me.id) @@ -670,7 +670,7 @@ def MoveFileToRecycleBin(job,del_me): parent_dir=session.query(Dir).join(PathDirLink).filter(PathDirLink.path_id==bin_path.id).first() print( f"need to keep this (ind): {del_me.in_dir.in_path.path_prefix}" ) - # if we ever need to undelete, lets remember this file's original path + # if we ever need to restore, lets remember this file's original path # (use a string in case the dir/path is ever deleted from FS (and then DB) and we need to recreate) del_file_details = DelFile( file_eid=del_me.id, orig_path_prefix=del_me.in_dir.in_path.path_prefix ) session.add( del_file_details ) @@ -1178,14 +1178,14 @@ def JobDeleteFiles(job): FinishJob(job, f"Finished deleting selected file(s)") return -def JobUnDeleteFiles(job): - AddLogForJob(job, f"INFO: Starting Undelete Files job...") +def JobRestoreFiles(job): + AddLogForJob(job, f"INFO: Starting Restore Files job...") for jex in job.extra: if 'eid-' in jex.name: restore_me=session.query(Entry).join(File).filter(Entry.id==jex.value).first() AddLogForJob(job, f"INFO: Removing file: #{restore_me.id} -> {restore_me}" ) - UnDeleteFile(job,restore_me) - FinishJob(job, f"Finished undeleting selected file(s)") + RestoreFile(job,restore_me) + FinishJob(job, f"Finished restoring selected file(s)") return def ValidateSettingsPaths(): diff --git a/templates/files.html b/templates/files.html index 88347b4..b127ec0 100644 --- a/templates/files.html +++ b/templates/files.html @@ -246,10 +246,10 @@ function DelDBox(del_or_undel) if( del_or_undel == "Delete" ) div+="'/delete_files', " else - div+="'/undelete_files', " + div+="'/restore_files', " div+=` data: to_del, - success: function(data){ console.log('Delete File(s) succeeded - TODO: need a FE msg' ); return false; } })" class="btn btn-outline-danger col-lg-2">Ok + success: function(data){ console.log('Delete/Restore File(s) succeeded - TODO: need a FE msg' ); return false; } })" class="btn btn-outline-danger col-lg-2">Ok ` $('#dbox-content').html(div) @@ -340,7 +340,7 @@ $.contextMenu({ view: { name: "View File" }, sep: "---", move: { name: "Move selected file(s) to new storage folder" }, - undel: { name: "Undelete Selected file(s)" } + undel: { name: "Restore selected file(s)" } } } else { item_list = {