diff options
Diffstat (limited to 'core/views/expo.py')
-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)) |