fix cave description view

This commit is contained in:
Philip Sargent 2021-04-01 20:08:57 +01:00
parent 573dba4712
commit f752f934b6
2 changed files with 38 additions and 14 deletions

View File

@ -137,6 +137,35 @@ def cave3d(request, cave_id=''):
# You can also set any other required headers: Cache-Control, etc. # You can also set any other required headers: Cache-Control, etc.
return response return response
def cavepage(request, karea, subpath):
'''Displays a cave description page'''
path = karea + subpath
print(" ! cavepage:'{}' kataster area:'{}' rest of path:'{}'".format(path, karea, subpath))
try:
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})
except Cave.MultipleObjectsReturned:
caves = Cave.objects.filter(url = path)
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
except:
return render(request, 'pagenotfound.html', {'path': path})
def caveSlug(request, 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})
def cave(request, cave_id='', offical_name=''): def cave(request, cave_id='', offical_name=''):
try: try:
cave=getCave(cave_id) cave=getCave(cave_id)
@ -173,6 +202,7 @@ def caveQMs(request, slug):
return render(request,'nonpublic.html', {'instance': cave}) return render(request,'nonpublic.html', {'instance': cave})
else: else:
return render(request,'cave_qms.html', {'cave': cave}) return render(request,'cave_qms.html', {'cave': cave})
def caveLogbook(request, slug): def caveLogbook(request, slug):
cave = Cave.objects.get(caveslug__slug = slug) cave = Cave.objects.get(caveslug__slug = slug)
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
@ -180,13 +210,6 @@ def caveLogbook(request, slug):
else: else:
return render(request,'cave_logbook.html', {'cave': cave}) return render(request,'cave_logbook.html', {'cave': cave})
def caveSlug(request, 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})
@login_required_if_public @login_required_if_public
def edit_cave(request, slug=None): def edit_cave(request, slug=None):
if slug is not None: if slug is not None:
@ -323,7 +346,7 @@ def get_qms(request, caveslug):
cave = Cave.objects.get(caveslug__slug = caveslug) cave = Cave.objects.get(caveslug__slug = caveslug)
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
areanames = [ AREANAMES = [
#('', 'Location unclear'), #('', 'Location unclear'),
('1a', '1a – Plateau: around Top Camp'), ('1a', '1a – Plateau: around Top Camp'),
('1b', '1b – Western plateau near 182'), ('1b', '1b – Western plateau near 182'),
@ -351,11 +374,11 @@ areanames = [
def prospecting(request): def prospecting(request):
#for key, name in areanames: #for key, name in AREANAMES:
# print key, Area.objects.get(short_name = key) #print(key, Area.objects.get(short_name = key))
areas = [] areas = []
for key, name in areanames: for key, name in AREANAMES:
a = Area.objects.get(short_name = key) a = Area.objects.get(short_name = key) # assumes unique
caves = list(a.cave_set.all()) caves = list(a.cave_set.all())
caves.sort(key=caveKey) caves.sort(key=caveKey)
areas.append((name, a, caves)) areas.append((name, a, caves))

View File

@ -8,7 +8,7 @@ from django.urls import reverse, resolve
from troggle.core.views import surveys, logbooks, other, caves, statistics, survex from troggle.core.views import surveys, logbooks, other, caves, statistics, survex
from troggle.core.views.other import troggle404, frontpage from troggle.core.views.other import troggle404, frontpage
from troggle.core.views.caves import ent, prospecting_image from troggle.core.views.caves import ent, prospecting_image, cavepage
from troggle.core.views.statistics import pathsreport, stats from troggle.core.views.statistics import pathsreport, stats
from troggle.core.views.expo import expofiles_redirect, expofilessingle, expopage, editexpopage, mediapage from troggle.core.views.expo import expofiles_redirect, expofilessingle, expopage, editexpopage, mediapage
from troggle.core.views.survex import survexcaveslist, survexcavesingle, svx from troggle.core.views.survex import survexcaveslist, survexcavesingle, svx
@ -97,7 +97,6 @@ trogglepatterns = [
url(r'^entrance/(?P<caveslug>[^/]+)/(?P<slug>[^/]+)/edit/', caves.editEntrance, name = "editentrance"), url(r'^entrance/(?P<caveslug>[^/]+)/(?P<slug>[^/]+)/edit/', caves.editEntrance, name = "editentrance"),
url(r'^entrance/new/(?P<caveslug>[^/]+)/', caves.editEntrance, name = "newentrance"), url(r'^entrance/new/(?P<caveslug>[^/]+)/', caves.editEntrance, name = "newentrance"),
url(r'^prospecting_guide/$', caves.prospecting),
url(r'^logbooksearch/(.*)/?$', logbooks.logbookSearch), url(r'^logbooksearch/(.*)/?$', logbooks.logbookSearch),
url(r'^statistics/?$', statistics.stats, name="stats"), url(r'^statistics/?$', statistics.stats, name="stats"),
@ -130,6 +129,7 @@ trogglepatterns = [
# url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"), # url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"),
url(r'^tunneldataraw/(?P<path>.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"), url(r'^tunneldataraw/(?P<path>.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"),
url(r'^prospecting_guide/$', caves.prospecting),
url(r'^prospecting/(?P<name>[^.]+).png$', prospecting_image, name="prospecting_image"), url(r'^prospecting/(?P<name>[^.]+).png$', prospecting_image, name="prospecting_image"),
@ -137,6 +137,7 @@ trogglepatterns = [
url(r'^site_media/(?P<subpath>.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # MEDIA_ROOT: CSS and JS url(r'^site_media/(?P<subpath>.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # MEDIA_ROOT: CSS and JS
url(r'^static/(?P<subpath>.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # STATIC is in MEDIA now! url(r'^static/(?P<subpath>.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # STATIC is in MEDIA now!
url(r'^(?P<karea>\d\d\d\d)(?P<subpath>.*)$', cavepage, name="cavepage"), # Cave description
url(r'^(.*)_edit$', editexpopage, name="editexpopage"), url(r'^(.*)_edit$', editexpopage, name="editexpopage"),
url(r'^(.*)$', expopage, name="expopage"), # CATCHALL assumed relative to EXPOWEB url(r'^(.*)$', expopage, name="expopage"), # CATCHALL assumed relative to EXPOWEB