mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 22:57:14 +00:00
Survex 1624, 1626, 1627 now displayed robustly
This commit is contained in:
@@ -11,7 +11,7 @@ from django.shortcuts import render_to_response, render
|
||||
from django.template.context_processors import csrf
|
||||
from django.http import HttpResponse, Http404
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
|
||||
import troggle.settings as settings
|
||||
import parsers.survex
|
||||
@@ -298,49 +298,32 @@ def identifycavedircontents(gcavedir):
|
||||
subsvx.insert(0, primesvx)
|
||||
return subdirs, subsvx
|
||||
|
||||
def check_cave_registered(survex_cave):
|
||||
'''Checks whether a cave has been properly registered when it is found in the Loser repo
|
||||
This should be called by Databasereset not here in a view
|
||||
Currently Caves are only registered if they are listed in :expoweb: settings.CAVEDESCRIPTIONS
|
||||
so we need to add in any mroe here.
|
||||
'''
|
||||
try:
|
||||
cave = Cave.objects.get(kataster_number=survex_cave)
|
||||
return survex_cave
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
try:
|
||||
cave = Cave.objects.get(unofficial_number=survex_cave)
|
||||
if cave.kataster_number:
|
||||
return cave.kataster_number
|
||||
else:
|
||||
return None
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
def get_survexareapath(area):
|
||||
return survexdatasetpath / str("caves-" + area)
|
||||
|
||||
# direct local non-database browsing through the svx file repositories
|
||||
# perhaps should use the database and have a reload button for it
|
||||
# why is caves-1623 HARD CODED here ?! That must be wrong..
|
||||
# every time the page is viewed! Should cache this.
|
||||
def survexcaveslist(request):
|
||||
'''This reads the entire list of caves in the Loser repo directory and produces a complete report.
|
||||
It can find caves which have not yet been properly registered in the system by Databasereset.py because
|
||||
someone may have uploaded the survex files without doing the rest of the integration process.
|
||||
'''
|
||||
cavesdir = survexdatasetpath / "caves-1623"
|
||||
#cavesdircontents = { }
|
||||
|
||||
# TO DO - filter out the non-public caves from display UNLESS LOGGED INS
|
||||
onefilecaves = [ ]
|
||||
multifilecaves = [ ]
|
||||
subdircaves = [ ]
|
||||
fnumlist = [ ]
|
||||
|
||||
# first sort the file list
|
||||
fnumlist = sorted([ (-int(re.match(r"\d*", f).group(0) or "0"), f) for f in os.listdir(cavesdir) ])
|
||||
for area in ["1623", "1626", "1624", "1627"]:
|
||||
cavesdir = get_survexareapath(area)
|
||||
arealist = sorted([ (area, -int(re.match(r"\d*", f).group(0) or "0"), f) for f in os.listdir(cavesdir) ])
|
||||
fnumlist += arealist
|
||||
|
||||
#print(fnumlist)
|
||||
print(fnumlist)
|
||||
|
||||
# go through the list and identify the contents of each cave directory
|
||||
for num, cavedir in fnumlist:
|
||||
for area, num, cavedir in fnumlist:
|
||||
|
||||
# these have sub dirs /cucc/ /arge/ /old/ but that is no reason to hide them in this webpage
|
||||
# so these are now treated the same as 142 and 113 which also have a /cucc/ sub dir
|
||||
@@ -350,14 +333,15 @@ def survexcaveslist(request):
|
||||
# This all assumes that the first .svx file has the same name as the cave name,
|
||||
# which usually but not always true. e.g. caves-1623/78/allkaese.svx not caves-1623/78/78.svx
|
||||
# which is why we now also pass through the cavedir
|
||||
cavesdir = get_survexareapath(area)
|
||||
gcavedir = os.path.join(cavesdir, cavedir)
|
||||
if os.path.isdir(gcavedir) and cavedir[0] != ".":
|
||||
subdirs, subsvx = identifycavedircontents(gcavedir)
|
||||
|
||||
katast = check_cave_registered(cavedir) # should do this only once per database load or it will be slow
|
||||
caveid = check_cave_registered(area, cavedir) # should do this only once per database load or it will be slow
|
||||
survdirobj = [ ]
|
||||
for lsubsvx in subsvx:
|
||||
survdirobj.append(("caves-1623/"+cavedir+"/"+lsubsvx, lsubsvx))
|
||||
survdirobj.append(("caves-" +area+ "/" +cavedir+"/"+lsubsvx, lsubsvx))
|
||||
|
||||
# caves with subdirectories
|
||||
if subdirs:
|
||||
@@ -367,7 +351,7 @@ def survexcaveslist(request):
|
||||
# assert not dsubdirs # handle case of empty sub directory
|
||||
lsurvdirobj = [ ]
|
||||
for lsubsvx in dsubsvx:
|
||||
lsurvdirobj.append(("caves-1623/"+cavedir+"/"+subdir+"/"+lsubsvx, lsubsvx))
|
||||
lsurvdirobj.append(("caves-" +area+ "/" +cavedir+"/"+subdir+"/"+lsubsvx, lsubsvx))
|
||||
if len(dsubsvx) >= 1:
|
||||
subsurvdirs.append((subdir,lsurvdirobj[0], lsurvdirobj[0:])) # list now includes the first item too
|
||||
subdircaves.append((cavedir, (survdirobj[0], survdirobj[1:]), subsurvdirs))
|
||||
@@ -384,24 +368,63 @@ def survexcaveslist(request):
|
||||
def survexcavesingle(request, survex_cave):
|
||||
'''parsing all the survex files of a single cave and showing that it's consistent and can find all
|
||||
the files and people. Should explicity fix the kataster number thing.
|
||||
kataster numbers are not unique across areas. Fix this.
|
||||
'''
|
||||
sc = survex_cave
|
||||
|
||||
try:
|
||||
cave = Cave.objects.get(kataster_number=sc)
|
||||
cave = Cave.objects.get(kataster_number=sc) # This may not be unique.
|
||||
return render_to_response('svxcavesingle.html', {'settings': settings, "cave":cave })
|
||||
|
||||
except ObjectDoesNotExist:
|
||||
# can get here if the survex file is in a directory labelled with unofficial number not kataster number.
|
||||
# maybe - and _ mixed up, or CUCC-2017- instead of 2017-CUCC-, or CUCC2015DL01 . Let's not get carried away..
|
||||
for unoff in [sc, sc.replace('-','_'), sc.replace('_','-')]:
|
||||
for unoff in [sc, sc.replace('-','_'), sc.replace('_','-'), sc.replace('-',''), sc.replace('_','')]:
|
||||
try:
|
||||
cave = Cave.objects.get(unofficial_number=unoff)
|
||||
cave = Cave.objects.get(unofficial_number=unoff) # return on first one we find
|
||||
return render_to_response('svxcavesingle.html', {'settings': settings, "cave":cave })
|
||||
except ObjectDoesNotExist:
|
||||
continue
|
||||
continue # next attempt in for loop
|
||||
return render_to_response('svxcavesingle404.html', {'settings': settings, "cave":sc })
|
||||
|
||||
except MultipleObjectsReturned:
|
||||
caves = Cave.objects.filter(kataster_number=survex_cave)
|
||||
return render_to_response('svxcaveseveral.html', {'settings': settings, "caves":caves })
|
||||
|
||||
except:
|
||||
return render_to_response('svxcavesingle404.html', {'settings': settings, "cave":sc })
|
||||
|
||||
|
||||
def check_cave_registered(area, survex_cave):
|
||||
'''Checks whether a cave has been properly registered when it is found in the Loser repo
|
||||
This should be called by Databasereset not here in a view
|
||||
Currently Caves are only registered if they are listed in :expoweb: settings.CAVEDESCRIPTIONS
|
||||
so we need to add in any more here.
|
||||
|
||||
This function runs but does not seem to be used?!
|
||||
'''
|
||||
try:
|
||||
cave = Cave.objects.get(kataster_number=survex_cave)
|
||||
return str(cave)
|
||||
|
||||
except MultipleObjectsReturned:
|
||||
caves = Cave.objects.filter(kataster_number=survex_cave)
|
||||
for c in caves:
|
||||
if str(c) == area + "-" + survex_cave :
|
||||
return str(c) # just get the first that matches
|
||||
return None # many returned but none in correct area
|
||||
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
try:
|
||||
cave = Cave.objects.get(unofficial_number=survex_cave) # should be unique!
|
||||
if cave.kataster_number:
|
||||
return str(cave)
|
||||
else:
|
||||
return None
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user