2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 11:07:08 +00:00

caves->wallets at parse time

This commit is contained in:
2023-10-23 03:24:34 +03:00
parent 54ffab3e93
commit 2b96086535
4 changed files with 21 additions and 60 deletions

View File

@@ -53,14 +53,15 @@ def populatewallet(w):
def caveifywallet(w):
"""Gets the caves from the list of survex files,
If called from survex parser, we never need to call it from a view too.
"""
# print(f' - Caveify {w=}')
blocknames = []
blocks = SurvexBlock.objects.filter(scanswallet=w)
for b in blocks:
# NB b.cave is not populated by parser. Use b.survexfile.cave instead, or we could parse b.survexpath
if b.survexfile.cave:
w.caves.add(b.survexfile.cave)
#if b.survexfile.cave:
#w.caves.add(b.survexfile.cave)
if b.name:
blocknames.append(b.name)
@@ -337,52 +338,7 @@ def cavewallets(request, caveid):
else:
return render(request, "errors/badslug.html", {"badslug": f"{caveid} - from cavewallets()"})
# remove duplication. Sorting is done in the template
# But this only gets wallets which have survex files attached..
# wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave))
# all the ones without a survexblock attached via a *ref, search for match in JSON
# zilchwallets = set(Wallet.objects.exclude(survexblock__survexfile__cave=cave))
# for z in zilchwallets:
# zcaveid = z.cave() # read JSON
# if zcaveid:
# cleanid = str(zcaveid).strip("' []\"")
# if cleanid.find(',') != -1:
# # it's a list of cave ids
# wurl = f"/walletedit/{z.walletname.replace('#',':')}"
# message = f" ! In {z.walletname} cavewallets, we do not handle lists of cave ids yet '{cleanid}'"
# print(message)
# DataIssue.objects.update_or_create(parser="scans", message=message, url=wurl)
# # it's a list of cave ids as a string. Identify any orphan caves hidden here
# ids = cleanid.split(',')
# for i in ids:
# i = i.strip("' []'")
# if is_cave(z,i):
# fcave = Gcavelookup[i.strip("' []'")] # just sets it to the last one found. nasty. bug waiting to happen
# elif cleanid in Gcavelookup:
# fcave = Gcavelookup[cleanid]
# if str(fcave.slug()) == caveid:
# # print(f' - Found one ! {z.walletname=} {zcaveid=}')
# wallets.add(z)
# elif f"1623-{cleanid}" in Gcavelookup: # special hack for all the old wallets which are 1623
# fcave = Gcavelookup[f"1623-{cleanid}"]
# if str(fcave.slug()) == caveid:
# # print(f' - Found one ! {z.walletname=} {zcaveid=}')
# wallets.add(z)
# elif cleanid in ['surface', 'unknown', '']:
# # message = f" ! In {z.walletname} cavewallets, ignoring '{cleanid}' as not a cave"
# # print(message)
# pass
# else:
# wurl = f"/walletedit/{z.walletname.replace('#',':')}"
# message = f" ! In {z.walletname} cavewallets, there is an unrecognised cave name '{cleanid}', adding to pending list."
# print(message)
# DataIssue.objects.update_or_create(parser="scans", message=message, url=wurl)
# add_cave_to_pending_list(cleanid, z, f"an unrecognised cave name in {z.walletname}")
# or now:
wallets = cave.wallets.all()
manywallets = list(set(wallets))
@@ -447,5 +403,5 @@ def allscans(request):
# manywallets = Wallet.objects.all().prefetch_related('singlescan') fails as the link is defined on 'singlescan' not on 'wallet'
expeditions = Expedition.objects.all()
return render(
request, "manywallets.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions}
request, "walletsall.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions}
)