mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 16:57:10 +00:00
new method for /site-media/, /static/, /photos/
This commit is contained in:
@@ -90,7 +90,23 @@ def expowebpage(request, expowebpath, path):
|
||||
has_menu = True
|
||||
return render(request, 'flatpage.html', {'editable': editable, 'path': path, 'title': title,
|
||||
'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu})
|
||||
|
||||
|
||||
def mediapage(request, subpath=None, doc_root=None):
|
||||
'''This is for special prefixe paths /photos/ /site_media/, /static/ etc.
|
||||
as defined in urls.py . If given a directory, gives a failure page.
|
||||
'''
|
||||
# print(" - XXXXX_ROOT: {} ...{}".format(doc_root, subpath))
|
||||
if doc_root is not None:
|
||||
filetobeopened = Path(doc_root, subpath)
|
||||
if filetobeopened.is_dir():
|
||||
return render(request, 'nodirlist.html', {'path': subpath})
|
||||
try:
|
||||
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(subpath))
|
||||
except IOError:
|
||||
return render(request, 'pagenotfound.html', {'path': subpath})
|
||||
else:
|
||||
return render(request, 'pagenotfound.html', {'path': subpath})
|
||||
|
||||
|
||||
def expopage(request, path):
|
||||
'''Either renders an HTML page from expoweb with all the menus,
|
||||
@@ -128,17 +144,9 @@ def expopage(request, path):
|
||||
# the final / may have been appended by middleware if there was no page without it
|
||||
# do not redirect to a file path without the slash as we may get in a loop. Let the user fix it:
|
||||
return render(request, 'dirnotfound.html', {'path': path, 'subpath': path[0:-1]})
|
||||
|
||||
if path.startswith('site_media'): # BUT we may have missing files, directories or .html here too?!
|
||||
# print(" - MEDIA_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
|
||||
npath = path.replace("site_media", settings.MEDIA_ROOT)
|
||||
filetobeopened = os.path.normpath(npath)
|
||||
elif path.startswith("static"):
|
||||
# print(" - STATIC_ROOT: {} ...{}".format(settings.MEDIA_ROOT, path))
|
||||
npath = path.replace("static", settings.MEDIA_ROOT)
|
||||
filetobeopened = os.path.normpath(npath)
|
||||
else:
|
||||
filetobeopened = os.path.normpath(expowebpath / path)
|
||||
|
||||
# So it must be a file in /expoweb/ but not .htm or .html probably an image
|
||||
filetobeopened = os.path.normpath(expowebpath / path)
|
||||
|
||||
try:
|
||||
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(path))
|
||||
|
||||
Reference in New Issue
Block a user