diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-03-31 23:19:48 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-03-31 23:19:48 +0100 |
commit | 269020391240f15d5d5997f88b51f401abf37cb1 (patch) | |
tree | 75cf2d8802bf0d0abe583e25f6b012d77d484f8c /core | |
parent | 9d8a44696bfcd045d64acb7d6eb0038a721cd8f3 (diff) | |
download | troggle-269020391240f15d5d5997f88b51f401abf37cb1.tar.gz troggle-269020391240f15d5d5997f88b51f401abf37cb1.tar.bz2 troggle-269020391240f15d5d5997f88b51f401abf37cb1.zip |
new method for /site-media/, /static/, /photos/
Diffstat (limited to 'core')
-rw-r--r-- | core/views/expo.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/core/views/expo.py b/core/views/expo.py index 4ca6f22..b62a3db 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -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)) |