From 7fc058b1da96d66020abdfd8dd7791bc981733b5 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 31 Jul 2023 22:00:46 +0300 Subject: [PATCH] return to correct wallet --- core/views/uploads.py | 32 ++++++++++++++++++++++++-------- templates/renameform.html | 9 ++++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index 04f486d..6b6b007 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -78,23 +78,39 @@ def expofilerename(request, filepath): message = f'\n Can only do rename within wallets (expofiles/surveyscans/) currently, sorry. "{actualpath}" ' print(message) return render(request, "errors/generic.html", {"message": message}) - - + if request.method == "POST": form = ExpofileRenameForm(request.POST) - if form.is_valid(): + if not form.is_valid(): + message = f'Invalid form response for file renaming "{request.POST}"' + print(message) + return render(request, "errors/generic.html", {"message": message}) + else: renameto = request.POST["renameto"] - if (folder / renameto).is_file(): - message = f'\n Cannot rename to an existing file. "{filename}" -> "{(folder / renameto)}"' + if (folder / renameto).is_file() or (folder / renameto).is_dir(): + rename_bad = renameto + message = f'\n Cannot rename to an existing file or folder. "{filename}" -> "{(folder / renameto)}"' print(message) - return render(request, "errors/generic.html", {"message": message}) + return render( + request, + "renameform.html", + { + "form": form, + "filepath": filepath, + "filename": filename, + "filesize": filesize, + "rename_bad": rename_bad, + }, + ) else: actualpath.rename((folder / renameto)) message = f'\n RENAMED "{filename}" -> "{(folder / renameto)}"' print(message) - return redirect('/survey_scans/2023%252314/') - + walletid = actualpath.relative_to(Path(settings.SCANS_ROOT)).parent.stem.replace("#",":") + print(walletid) + return redirect(f'/survey_scans/{walletid}/') + else: form = ExpofileRenameForm() return render( diff --git a/templates/renameform.html b/templates/renameform.html index cda8bbf..aae489b 100644 --- a/templates/renameform.html +++ b/templates/renameform.html @@ -4,14 +4,21 @@ {% block content %} -

Rename "{{filename}}"

+

Renaming "{{filename}}"

filesize: {{filesize}} bytes
+ {% if rename_bad %} +

+ + Cannot rename to '{{rename_bad}}' as a file (or a subfolder) of that name already exists here. +

+ {% endif %}
+
{% csrf_token %}