From 9870c00c914213c41f732bfe29d3bad223175033 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 18 Dec 2025 23:36:22 +0000 Subject: [PATCH] tidied survex file editing error conditions --- core/views/survex.py | 33 +++++++++++++++++++-------------- urls.py | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/core/views/survex.py b/core/views/survex.py index 3af30dc..224f98e 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -658,42 +658,47 @@ def get_primaries(cave): sds.append(sp) return list(set(sds)) -def survexcavesingle(request, cave_shortname): +def survex_by_cave_id(request, svx_filepath): """parsing all the survex files of a single cave and showing that it's consistent and can find all the files and people. - But might also be a link to a single survex file with no ".svx" suffix, which may not be a cave. + 'svx_filepath' might be 'caves-1623/264/264" or it might be "surface/1623/78to78d + If it ends in .svx it will be sent straight to svx() - If cave_shortname=="" then it used to list all caves which did not have a kataser number, + But might also be a link to a single survex file with no ".svx" suffix. + + If svx_filepath=="" then it used to list all caves which did not have a kataser number, an accident of coding. This now does not happen because urls.py has been changed to stop it. """ - if cave_shortname.startswith("caves-16"): - return svx(request, cave_shortname) + # These are the editable folders below 'loser' + prefixes = ("fixedpts", "gpx", "kataster", "subsections", "surface", "template", "caves-16") + if svx_filepath.startswith(prefixes): # then it is a survex file, not a cave id + return svx(request, svx_filepath) Gcavelookup = GetCaveLookup() - if cave_shortname in Gcavelookup: - cave = Gcavelookup[cave_shortname] - # print(f"survexcavesingle {cave_shortname=} => {cave=}") + if svx_filepath in Gcavelookup: + cave = Gcavelookup[svx_filepath] + # print(f"survex_by_cave_id {svx_filepath=} => {cave=}") cave.sds = get_primaries(cave) return render(request, "svxcaves.html", {"settings": settings, "caves": [cave], "year": current_expo()}) else: - caves = Cave.objects.filter(kataster_number=cave_shortname) + caves = Cave.objects.filter(kataster_number=svx_filepath) if len(caves) > 0: - # print(f"many {cave_shortname=} => {caves=}") + # print(f"many {svx_filepath=} => {caves=}") for cave in caves: cave.sds = get_primaries(cave) # print(f"many {cave=} => {cave.sds=}") return render(request, "svxcaves.html", {"settings": settings, "caves": caves, "year": current_expo()}) else: # A decision needs to be made: is this a silly thing or is it a real file? - filepath = settings.SURVEX_DATA / cave_shortname + filepath = settings.SURVEX_DATA / svx_filepath + print(f" - {filepath=}\n - {svx_filepath=}") if filepath.is_file(): - print(filepath, type(filepath)) # survex file not a cave, e.g. surface/1623/allsurface.svx - return svx(request, cave_shortname) + return svx(request, svx_filepath) else: - return render(request, "errors/svxcaves404.html", {"settings": settings, "cave": cave_shortname, "year": current_expo()}) + return render(request, "errors/svxcaves404.html", {"settings": settings, "cave": svx_filepath, "year": current_expo()}) def check_cave_registered(areacode, survex_cave): """Checks whether a cave has been properly registered when it is found in the Loser repo diff --git a/urls.py b/urls.py index b03ec5d..924f5bb 100644 --- a/urls.py +++ b/urls.py @@ -296,14 +296,14 @@ trogglepatterns = [ # The survexfile pages path('survexdir', survex.survexdir, name="survexdir"), - # path('survexfile', survex.survexcavesingle, {'cave_shortname': ''}, name="survexcavessingle"), + # path('survexfile', survex.survex_by_cave_id, {'svx_filepath': ''}, name="survex_by_cave_id"), path('survexfile/caves', survex.survexcaveslist, name="survexcaveslist"), path('survexfile/.svx', survex.svx, name="svx"), path('survexfile/.3d', survex.threed, name="threed"), path('survexfile/.log', survex.svxlog, name="svxlog"), path('survexfile/.err', survex.err, name="err"), - path('survexfile/', survex.survexcavesingle, name="survexcavessingle"), + path('survexfile/', survex.survex_by_cave_id, name="survex_by_cave_id"), path('survexfilewild', statistics.svxfilewild, name="svxfilewild"), path('survexfilewild/', statistics.svxfilewild, name="svxfilewild"),