From c8cc1673e0d5329d369a35ff22eedf141e2d2a74 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 1 Apr 2021 21:44:03 +0100 Subject: [PATCH] enable non-cave html and images redirection --- core/views/caves.py | 11 ++++++++--- core/views/expo.py | 7 ++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/views/caves.py b/core/views/caves.py index 2a1e726..1f89376 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -15,6 +15,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned import troggle.settings as settings #import troggle.core.models as models +from troggle.core.views import expo from troggle.core.models import Expedition, DataIssue from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm @@ -138,7 +139,11 @@ def cave3d(request, cave_id=''): return response def cavepage(request, karea, subpath): - '''Displays a cave description page''' + '''Displays a cave description page + + There are A LOT OF URLS to e.g. /1623/161/l/rl89a.htm which are IMAGES and html files + in cave descriptions. These need to be handled HERE + ''' path = karea + subpath print(" ! cavepage:'{}' kataster area:'{}' rest of path:'{}'".format(path, karea, subpath)) @@ -146,13 +151,13 @@ def cavepage(request, karea, subpath): cave = Cave.objects.get(url = path) # ideally this will be unique slug = cave.slug() print(" - cavepage:'{}' cave:'{}' cave-slug:'{}'".format(path, str(cave), slug)) - #cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug}) else: return render(request,'cave.html', {'cave': cave, 'cave_editable': slug}) except Cave.DoesNotExist: - return render(request, 'pagenotfound.html', {'path': path}) + # probably a link to text or an image e.g. 1623/161/l/rl89a.htm i.e. an expoweb page + return expo.expopage(request, path) except Cave.MultipleObjectsReturned: caves = Cave.objects.filter(url = path) return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves }) diff --git a/core/views/expo.py b/core/views/expo.py index b62a3db..07cb9c2 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -18,8 +18,8 @@ from troggle.core.models_caves import Cave import troggle.core.views.caves import troggle.settings as settings -'''Formerly a separate package 'flatpages' written by Martin Green 2011. -This was NOT django.contrib.flatpages which stores HTML in the database, so the name was chnaged to expopages. +'''Formerly a separate package called 'flatpages' written by Martin Green 2011. +This was NOT django.contrib.flatpages which stores HTML in the database, so the name was changed to expopages. Then it was incorporated into troggle directly, rather than being an unnecessary external package. ''' @@ -92,7 +92,7 @@ def expowebpage(request, expowebpath, path): '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. + '''This is for special prefix 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)) @@ -108,6 +108,7 @@ def mediapage(request, subpath=None, doc_root=None): return render(request, 'pagenotfound.html', {'path': subpath}) + def expopage(request, path): '''Either renders an HTML page from expoweb with all the menus, or serves an unadorned binary file with mime type