2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

caves->wallets at parse time

This commit is contained in:
Philip Sargent 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,51 +338,6 @@ 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()
@ -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}
)

View File

@ -55,6 +55,8 @@ def import_survex():
with transaction.atomic():
troggle.parsers.survex.LoadSurvexBlocks()
print(" - Survex entrances x/y/z Positions")
with transaction.atomic():
troggle.parsers.survex.caveifywallets()
with transaction.atomic():
troggle.parsers.locations.LoadPositions()

View File

@ -2481,6 +2481,17 @@ def MakeFileRoot(svxpath):
return fileroot
def caveifywallets():
"""Gets the caves from the list of survexblocks
"""
wallets = Wallet.objects.all()
for w in wallets:
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)
def LoadSurvexBlocks():
global dup_includes
@ -2537,3 +2548,5 @@ def LoadSurvexBlocks():
print(f" - ERROR: There are {dup_includes} duplicate *includes in the final list")
print(" - Loaded All Survex Blocks.")

View File

@ -29,7 +29,7 @@ see https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related
-->
<table width=95%>
<tr><th>Scans folder</th><th>Files</th><th>Survex blocks</th><th>Cave (new)</th><th>Cave (old)</th></tr>
<tr><th>Scans folder</th><th>Files</th><th>Survex blocks</th><th>Cave</th></tr>
{% for wallet in manywallets %}
<tr>
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
@ -46,17 +46,7 @@ see https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related
{% endfor %}
</td>
<td style="padding:2px">
{% for survexblock in wallet.survexblock_set.all %}
{% ifchanged survexblock.survexfile.cave %}
<a href="/cave/scans/{{survexblock.survexfile.cave.slug}}">{{survexblock.survexfile.cave.slug}}</a>
{% endifchanged %}
{% empty %}
{% if wallet.cave %}
<em><a href="/cave/scans/{{wallet.cave}}">{{wallet.cave}}</a></em>
{% endif %}
{% endfor %}
</td>
</tr>
{% endfor %}