2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-16 06:57:12 +00:00

Fixed survex file list for one or more caves

This commit is contained in:
2023-09-06 13:20:29 +03:00
parent 38d0e855c9
commit 83d058221d
6 changed files with 50 additions and 159 deletions

View File

@@ -17,7 +17,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
import troggle.settings as settings
from troggle.core.models.logbooks import LogbookEntry
from troggle.core.models.caves import Cave
from troggle.core.models.caves import Cave, GetCaveLookup
from troggle.core.models.survex import SurvexFile, SurvexBlock, SurvexDirectory
from troggle.core.models.wallets import Wallet
from troggle.core.utils import only_commit
@@ -670,43 +670,41 @@ def survexdir(request):
# print(f, f.cave)
return render(request, "survexdir.html", {"survexdirs": sds, "survexfiles": survexfiles})
def survexcavesingle(request, survex_cave):
def get_directories(cave):
sds = []
sfs = cave.survexfile_set.all()
for sf in sfs:
sds.append(sf.survexdirectory)
return list(set(sds))
def survexcavesingle(request, cave_shortname):
"""parsing all the survex files of a single cave and showing that it's consistent and can find all
the files and people. Should explicitly fix the kataster number thing.
kataster numbers are not unique across areas. This used to be a db constraint but we need to manage
this ourselves as we don't want the parser aborting with an error message.
Should use getCave() from models_caves
the files and people.
"""
sc = survex_cave
try:
cave = Cave.objects.get(kataster_number=sc) # This may not be unique.
return render(request, "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..
# or it might be an exact search for a specific survefile but just missing the '.svx.
if (SVXPATH / Path(survex_cave + ".svx")).is_file():
return svx(request, survex_cave)
for unoff in [sc, sc.replace("-", "_"), sc.replace("_", "-"), sc.replace("-", ""), sc.replace("_", "")]:
try:
cave = Cave.objects.get(unofficial_number=unoff) # return on first one we find
return render(request, "svxcavesingle.html", {"settings": settings, "cave": cave})
except ObjectDoesNotExist:
continue # next attempt in for loop
return render(request, "errors/svxcavesingle404.html", {"settings": settings, "cave": sc})
except MultipleObjectsReturned:
caves = Cave.objects.filter(kataster_number=survex_cave)
return render(request, "svxcaveseveral.html", {"settings": settings, "caves": caves})
except:
return render(request, "errors/svxcavesingle404.html", {"settings": settings, "cave": sc})
Gcavelookup = GetCaveLookup()
if cave_shortname in Gcavelookup:
cave = Gcavelookup[cave_shortname]
# print(f"survexcavesingle {cave_shortname=} => {cave=}")
cave.sds = get_directories(cave)
return render(request, "svxcaves.html", {"settings": settings, "caves": [cave]})
else:
# not a cave or an ambiguous short name, e.g. "122"
# if (SVXPATH / Path(cave_shortname + ".svx")).is_file():
# return svx(request, cave_shortname)
caves = Cave.objects.filter(kataster_number=cave_shortname)
if len(caves) > 0:
# print(f"many {cave_shortname=} => {caves=}")
for cave in caves:
cave.sds = get_directories(cave)
# print(f"many {cave=} => {cave.sds=}")
return render(request, "svxcaves.html", {"settings": settings, "caves": caves})
else:
return render(request, "errors/svxcaves404.html", {"settings": settings, "cave": cave_shortname})
def check_cave_registered(area, survex_cave):
"""Checks whether a cave has been properly registered when it is found in the Loser repo
@@ -714,8 +712,8 @@ def check_cave_registered(area, survex_cave):
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?!
A serious bodge anyway.
This function is used in survexcaveslist(request)
A serious bodge.
"""
try:
cave = Cave.objects.get(kataster_number=survex_cave)