2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

return to correct wallet

This commit is contained in:
Philip Sargent 2023-07-31 22:00:46 +03:00
parent 8d9b320d89
commit 7fc058b1da
2 changed files with 32 additions and 9 deletions

View File

@ -78,23 +78,39 @@ def expofilerename(request, filepath):
message = f'\n Can only do rename within wallets (expofiles/surveyscans/) currently, sorry. "{actualpath}" ' message = f'\n Can only do rename within wallets (expofiles/surveyscans/) currently, sorry. "{actualpath}" '
print(message) print(message)
return render(request, "errors/generic.html", {"message": message}) return render(request, "errors/generic.html", {"message": message})
if request.method == "POST": if request.method == "POST":
form = ExpofileRenameForm(request.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"] renameto = request.POST["renameto"]
if (folder / renameto).is_file(): if (folder / renameto).is_file() or (folder / renameto).is_dir():
message = f'\n Cannot rename to an existing file. "{filename}" -> "{(folder / renameto)}"' rename_bad = renameto
message = f'\n Cannot rename to an existing file or folder. "{filename}" -> "{(folder / renameto)}"'
print(message) 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: else:
actualpath.rename((folder / renameto)) actualpath.rename((folder / renameto))
message = f'\n RENAMED "{filename}" -> "{(folder / renameto)}"' message = f'\n RENAMED "{filename}" -> "{(folder / renameto)}"'
print(message) 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: else:
form = ExpofileRenameForm() form = ExpofileRenameForm()
return render( return render(

View File

@ -4,14 +4,21 @@
{% block content %} {% block content %}
<h2>Rename "{{filename}}"</h2> <h2>Renaming "{{filename}}"</h2>
<a href="/expofiles/{{filepath|urlencode}}"> <a href="/expofiles/{{filepath|urlencode}}">
<figure class=onleft> <figure class=onleft>
<img src="/expofiles/{{filepath|urlencode}}" width=150px> <img src="/expofiles/{{filepath|urlencode}}" width=150px>
<figcaption>filesize: {{filesize}} bytes <figcaption>filesize: {{filesize}} bytes
</figcaption> </figcaption>
</figure></a> </figure></a>
{% if rename_bad %}
<p style="font-family: monospace; font-weight: bold; color: red; font-size: 130%; text-align: center">
Cannot rename to '{{rename_bad}}' as a file (or a subfolder) of that name already exists here.
</p>
{% endif %}
<div style = "max-width:95%; margin-left:8%; text-align: left; " > <div style = "max-width:95%; margin-left:8%; text-align: left; " >
<form method ='post' > <form method ='post' >
{% csrf_token %} {% csrf_token %}
<br> <br>