pathlib for path management & cavelist fixes

This commit is contained in:
Philip Sargent
2021-03-24 15:46:35 +00:00
parent 7f37327bcd
commit 9a91487375
5 changed files with 69 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import os
import re
from pathlib import Path
from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404
@@ -52,15 +53,16 @@ def flatpage(request, path):
print(("flat path noinfo", path))
return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path)
expowebpath = Path(settings.EXPOWEB)
if path.endswith("/") or path == "":
#print(" - FLATPAGES the file: {} ENDSWITH ...".format(path))
try:
o = open(os.path.normpath(settings.EXPOWEB + path + "index.html"), "rb")
o = open(os.path.normpath(expowebpath / path / "index.html"), "rb")
path = path + "index.html"
except IOError:
try:
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
o = open(os.path.normpath(expowebpath / path / "index.htm"), "rb")
path = path + "index.htm"
except IOError:
return render(request, 'pagenotfound.html', {'path': path})
@@ -77,8 +79,8 @@ def flatpage(request, path):
path = path.replace("static", settings.MEDIA_ROOT)
filetobeopened = os.path.normpath(path)
else:
#print(" - NO _ROOT: {} ...".format(settings.EXPOWEB))
filetobeopened = os.path.normpath(settings.EXPOWEB + path)
#print(" - NO _ROOT: {} ...".format(expowebpath))
filetobeopened = os.path.normpath(expowebpath / path)
#print(" - FLATPAGES full path : {} ...".format(filetobeopened))
o = open(filetobeopened, "rb")