2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-19 01:17:13 +00:00

Fixing multiple caves with same kataser no

This commit is contained in:
Philip Sargent
2021-03-28 23:47:47 +01:00
parent 0ecaa9b8ee
commit 623483f3b1
5 changed files with 97 additions and 53 deletions

View File

@@ -13,7 +13,6 @@ from django.views.decorators.csrf import ensure_csrf_cookie
import django.forms as forms
from troggle.helper import login_required_if_public
#from troggle.flatpages.models import Redirect, EntranceRedirect
from troggle.core.models_caves import Cave
import troggle.core.views_caves
import troggle.settings as settings
@@ -30,14 +29,14 @@ def expofilessingle(request, filepath):
fn = Path(settings.EXPOFILES,filepath)
if fn.is_dir():
return expofilesdir(request, Path(fn), Path(filepath))
print(" - expofilessingle {}:{}:{}:".format(filepath, fn, getmimetype(fn)))
# print(" - expofilessingle {}:{}:{}:".format(filepath, fn, getmimetype(fn)))
return HttpResponse(content=open(fn, "rb"),content_type=getmimetype(filepath)) # any file
def expofilesdir(request, dirpath, filepath):
'''does a directory display. If there is an index.html file we should display that.
- dirpath is a Path() and it does not have /expofiles/ in it
'''
print(" - expofilesdir {}".format(dirpath))
# print(" - expofilesdir {}".format(dirpath))
urlpath = 'expofiles' / Path(filepath)
fileitems = []
diritems = []
@@ -53,31 +52,19 @@ def expofilesdir(request, dirpath, filepath):
def flatpage(request, path):
'''Either renders an HTML page from expoweb with all the menus,
or serves an unadorned binary file with mime type'''
print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path)),flush=True)
or serves an unadorned binary file with mime type
This is a horrible mess and some code is redundant and unreachable because of urls.py setup
'''
# print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path)),flush=True)
if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated():
print((" - FLATPAGES redirect to logon: flat path noinfo", path))
# print((" - FLATPAGES redirect to logon: flat path noinfo", path))
return HttpResponseRedirect(urljoin(reverse("auth_login"),'?next={}'.format(request.path)))
try:
r = Cave.objects.get(url = path)
return troggle.core.views_caves.caveSlug(request, r.slug())
except Cave.DoesNotExist:
pass
except:
#print(" ! FAILED to get only one cave per slug for: "+path)
# we should do this proper;ly, not this hack that returns the first cave that matches
caves = Cave.objects.all().filter(url = path)
for c in caves:
print(path, c.slug())
if c.slug() != None:
return troggle.core.views_caves.caveSlug(request, c.slug())
pass
expowebpath = Path(settings.EXPOWEB)
if path.endswith("/") or path == "":
print(" - FLATPAGES the file: {} ENDSWITH ...".format(path))
# print(" - FLATPAGES the file: {} ENDSWITH ...".format(path))
try:
o = open(os.path.normpath(expowebpath / path / "index.html"), "rb")
@@ -89,25 +76,25 @@ def flatpage(request, path):
except IOError:
return render(request, 'pagenotfound.html', {'path': path})
else:
print(" - FLATPAGES the file: '{}' ...".format(path))
# print(" - FLATPAGES the file: '{}' ...".format(path))
if path.startswith('site_media'):
print(" - MEDIA_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
# print(" - MEDIA_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
path = path.replace("site_media", settings.MEDIA_ROOT)
filetobeopened = os.path.normpath(path)
elif path.startswith("static"):
print(" - STATIC_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
# print(" - STATIC_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
path = path.replace("static", settings.MEDIA_ROOT)
filetobeopened = os.path.normpath(path)
else:
print(" - NO _ROOT: {} ...".format(expowebpath))
# print(" - NO _ROOT: {} ...".format(expowebpath))
filetobeopened = os.path.normpath(expowebpath / path)
print(" - FLATPAGES full path : {} ...".format(filetobeopened))
# print(" - FLATPAGES full path : {} ...".format(filetobeopened))
try:
o = open(filetobeopened, "rb")
print(" - FLATPAGES full path no error: {} ...".format(filetobeopened))
#print(" - FLATPAGES full path no error: {} ...".format(filetobeopened))
except IOError:
print(" - FLATPAGES ERROR: {} ...".format(filetobeopened))
#print(" - FLATPAGES ERROR: {} ...".format(filetobeopened))
#o.close()
return render(request, 'pagenotfound.html', {'path': path})
@@ -147,7 +134,7 @@ def flatpage(request, path):
return render(request, 'flatpage.html', {'editable': editable, 'path': path, 'title': title,
'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu})
else:
print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path)))
# print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path)))
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(path))
#return HttpResponse(content=open(singlescan.ffile,"rb"), content_type=getmimetype(path))