mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
logic rearranged
This commit is contained in:
parent
724989f985
commit
0295fce110
@ -406,6 +406,26 @@ def expofilerename(request, filepath):
|
||||
Currently this just does files within wallets i.e. in /surveyscans/
|
||||
and it returns control to the original wallet edit page
|
||||
"""
|
||||
def rotate_image():
|
||||
print("ROTATE")
|
||||
return simple_get()
|
||||
|
||||
def simple_get():
|
||||
form = ExpofileRenameForm()
|
||||
return render(
|
||||
request,
|
||||
"renameform.html",
|
||||
{
|
||||
"form": form,
|
||||
"filepath": filepath,
|
||||
"filename": filename,
|
||||
"filesize": filesize,
|
||||
"files": files,
|
||||
"walletpath": walletpath,
|
||||
"notpics": notpics,
|
||||
},
|
||||
)
|
||||
|
||||
if filepath:
|
||||
actualpath = Path(settings.EXPOFILES) / Path(filepath)
|
||||
else:
|
||||
@ -419,6 +439,7 @@ def expofilerename(request, filepath):
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
else:
|
||||
filename = Path(filepath).name
|
||||
walletpath = Path(filepath).parent
|
||||
folder = actualpath.parent
|
||||
filesize = f"{actualpath.stat().st_size:,}"
|
||||
|
||||
@ -427,15 +448,47 @@ def expofilerename(request, filepath):
|
||||
print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
if request.method == "POST":
|
||||
files = []
|
||||
dirs = []
|
||||
notpics =[]
|
||||
dirpath = actualpath.parent
|
||||
print(f'! - FORM rename expofile - start \n{filepath=} \n{dirpath=} \n{walletpath=}')
|
||||
if dirpath.is_dir():
|
||||
try:
|
||||
for f in dirpath.iterdir():
|
||||
if f.is_dir():
|
||||
for d in f.iterdir():
|
||||
dirs.append(f"{f.name}/{d.name}")
|
||||
if f.is_file():
|
||||
if Path(f.name).suffix.lower() in [".jpg", ".jpeg", ".png"]:
|
||||
files.append(f.name)
|
||||
else:
|
||||
notpics.append(f.name)
|
||||
except FileNotFoundError:
|
||||
files.append(
|
||||
"(Error. There should be at least one filename visible here. Try refresh.)"
|
||||
)
|
||||
if request.method == "GET":
|
||||
return simple_get()
|
||||
|
||||
elif request.method == "POST":
|
||||
form = ExpofileRenameForm(request.POST)
|
||||
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 = sanitize_name(request.POST["renameto"])
|
||||
|
||||
if "rotate" in request.POST:
|
||||
return rotate_image()
|
||||
|
||||
if "rename" in request.POST:
|
||||
if "renametoname" not in request.POST:
|
||||
print("renametoname not in request.POST")
|
||||
# blank filename passed it, so just treat as another GET
|
||||
return simple_get()
|
||||
|
||||
|
||||
renameto = sanitize_name(request.POST["renametoname"])
|
||||
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)}"'
|
||||
@ -448,10 +501,13 @@ def expofilerename(request, filepath):
|
||||
"filepath": filepath,
|
||||
"filename": filename,
|
||||
"filesize": filesize,
|
||||
"files": files,
|
||||
"walletpath": walletpath,
|
||||
"notpics": notpics,
|
||||
"rename_bad": rename_bad,
|
||||
},
|
||||
)
|
||||
else:
|
||||
|
||||
actualpath.rename((folder / renameto))
|
||||
message = f'\n RENAMED "{filename}" -> "{(folder / renameto)}"'
|
||||
print(message)
|
||||
@ -459,18 +515,9 @@ def expofilerename(request, filepath):
|
||||
print(walletid)
|
||||
return redirect(f'/survey_scans/{walletid}/')
|
||||
|
||||
else:
|
||||
form = ExpofileRenameForm()
|
||||
return render(
|
||||
request,
|
||||
"renameform.html",
|
||||
{
|
||||
"form": form,
|
||||
"filepath": filepath,
|
||||
"filename": filename,
|
||||
"filesize": filesize,
|
||||
},
|
||||
)
|
||||
else: # not GET or POST
|
||||
print("UNRECOGNIZED action")
|
||||
return simple_get()
|
||||
|
||||
@login_required_if_public
|
||||
def photoupload(request, folder=None):
|
||||
|
Loading…
Reference in New Issue
Block a user