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.
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=''):
try:
cave=getCave(cave_id)
@ -173,6 +202,7 @@ def caveQMs(request, slug):
return render(request,'nonpublic.html', {'instance': cave})
else:
return render(request,'cave_qms.html', {'cave': cave})
def caveLogbook(request, slug):
cave = Cave.objects.get(caveslug__slug = slug)
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
@ -180,13 +210,6 @@ def caveLogbook(request, slug):
else:
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
def edit_cave(request, slug=None):
if slug is not None:
@ -323,7 +346,7 @@ def get_qms(request, 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()]})
areanames = [
AREANAMES = [
#('', 'Location unclear'),
('1a', '1a – Plateau: around Top Camp'),
('1b', '1b – Western plateau near 182'),
@ -351,11 +374,11 @@ areanames = [
def prospecting(request):
#for key, name in areanames:
# print key, Area.objects.get(short_name = key)
#for key, name in AREANAMES:
#print(key, Area.objects.get(short_name = key))
areas = []
for key, name in areanames:
a = Area.objects.get(short_name = key)
for key, name in AREANAMES:
a = Area.objects.get(short_name = key) # assumes unique
caves = list(a.cave_set.all())
caves.sort(key=caveKey)
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.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.expo import expofiles_redirect, expofilessingle, expopage, editexpopage, mediapage
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/new/(?P<caveslug>[^/]+)/', caves.editEntrance, name = "newentrance"),
url(r'^prospecting_guide/$', caves.prospecting),
url(r'^logbooksearch/(.*)/?$', logbooks.logbookSearch),
url(r'^statistics/?$', statistics.stats, name="stats"),
@ -130,6 +129,7 @@ trogglepatterns = [
# url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"),
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"),
@ -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'^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'^(.*)$', expopage, name="expopage"), # CATCHALL assumed relative to EXPOWEB