mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 22:57:07 +00:00
fixing bad url handling
This commit is contained in:
@@ -413,6 +413,9 @@ def cavepage(request, karea=None, subpath=None):
|
||||
cave = caves[0]
|
||||
return rendercave(request, cave, cave.slug())
|
||||
|
||||
if len(subpath) > 100: # overlong URL
|
||||
return redirect(f"/caves")
|
||||
|
||||
|
||||
# HORRIBLE HACK, to be removed..
|
||||
subpath = subpath.strip("//")
|
||||
@@ -420,6 +423,7 @@ def cavepage(request, karea=None, subpath=None):
|
||||
parts = subpath.strip("/").split("/")
|
||||
if len(parts) > 5:
|
||||
# recursive loop. break out of it.
|
||||
print(karea,subpath)
|
||||
subparts = parts[0].split(".")
|
||||
caveid = subparts[0]
|
||||
slug = f"{karea}-{caveid}"
|
||||
@@ -427,34 +431,39 @@ def cavepage(request, karea=None, subpath=None):
|
||||
return redirect(f"/{cave.url}")
|
||||
else:
|
||||
return redirect(f"/caves")
|
||||
|
||||
|
||||
|
||||
# epath = karea + subpath # e.g. 1623 /204
|
||||
# return expo.expopage(request, epath)
|
||||
|
||||
# BUGGER the real problem is the the cave descript has embedded in it images like
|
||||
|
||||
# BUGGER the real problem is the the cave description has embedded in it images like
|
||||
# src="110/entrance.jpeg and since the cave url is now /1623/110/110.html
|
||||
# the images try to load from /1623/110/110/entrance.jpeg and of course fail.
|
||||
# THIS IS A HORRIBLE HACK
|
||||
if len(parts) == 1:
|
||||
# simple filename, no folders in path,
|
||||
# either need to insert caveid OR leave as relative link as we are already "in" /1623/nn/
|
||||
# either need to insert caveid OR leave as relative link as we are already "in" /1623/nn/
|
||||
# if we are doing a cave description file
|
||||
print("SIMPLE", subpath, parts)
|
||||
subparts = parts[0].split(".")
|
||||
caveid = subparts[0] # e.g. 204.htm
|
||||
caveid = subparts[0] # e.g. 204.htm => "204"
|
||||
k2path = karea +"/"+ caveid + subpath
|
||||
return redirect(f"/{k2path}") # infinite loop
|
||||
return redirect(f"/{k2path}") # potential infinite loop
|
||||
elif len(parts) >2:
|
||||
# e.g. i/204.jpg, but that's ok as we are already "in" /1623/nn/
|
||||
if parts[0] == parts[1]: # double caveid
|
||||
if parts[0] == parts[1]: # double caveid, e.g. /161/161/france.html
|
||||
epath = karea
|
||||
for i in parts[1:]:
|
||||
epath += "/" + i
|
||||
#print(f"{subpath=}\n {epath=}")
|
||||
# print(f"{subpath=}\n {epath=}")
|
||||
return expo.expopage(request, epath)
|
||||
|
||||
# if either the first two parts are not /caveid/caveid/
|
||||
# or the number of parts == 2,
|
||||
# print(f"2 {subpath=}")
|
||||
# This is the bit that MOST images in descriptions get to.
|
||||
# simple filename, no folders in path, e.g. href="94_ent_close.jpg"
|
||||
# inside a cave or entrance description, this "just works" as the href is just
|
||||
# added to the context of the current page, so there are >> 1 "parts" to the URL.
|
||||
print(f"2 {subpath=}")
|
||||
epath = karea + "/" + subpath
|
||||
return expo.expopage(request, epath)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user