diff --git a/core/models/caves.py b/core/models/caves.py index 9336f5b..2494a4e 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -28,7 +28,7 @@ from troggle.core.models.survex import SurvexStation from troggle.core.utils import writetrogglefile from troggle.core.utils import TROG -# Us ethe TROG global object to cache teh cave lookup list +# Use the TROG global object to cache the cave lookup list Gcavelookup = TROG['caves']['gcavelookup'] Gcave_count = TROG['caves']['gcavecount'] diff --git a/core/views/scans.py b/core/views/scans.py index 4e256a6..1b9ab95 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -64,13 +64,14 @@ def caveifywallet(w): '''Gets the cave from the list of survex files, only selects one of them though. Only used for display. ''' + 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.cave = b.survexfile.cave # just gets the last one, randomly. SHould make this a list or many:many ideally - + w.caveobj = b.survexfile.cave # just gets the last one, randomly. SHould make this a list or many:many ideally + w.cave = w.caveobj if b.name: blocknames.append(b.name) @@ -98,9 +99,18 @@ def fillblankothers(w): if not w.date(): datewallet(w, earliest) - c = w.cave() - if not c or c == "": + Gcavelookup = GetCaveLookup() + + wcaveid = w.cave() + if not wcaveid or wcaveid == "": caveifywallet(w) + else: + if wcaveid in Gcavelookup: + w.caveobj = Gcavelookup[wcaveid] + # print(f' - Found cave object from id {wcaveid}') + else: + print(f' - Failed to find cave object from id {wcaveid}') + def fixsurvextick(w, ticks): ticks["S"] = w.fixsurvextick(ticks["S"]) @@ -189,17 +199,17 @@ def cavewallets(request, caveid): # 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: - zcave = z.cave() - if zcave: - if str(zcave) in Gcavelookup: - fcave = Gcavelookup[str(zcave)] + zcaveid = z.cave() + if zcaveid: + if str(zcaveid) in Gcavelookup: + fcave = Gcavelookup[str(zcaveid)] if str(fcave.slug()) == caveid: - # print(f' - Found one ! {z.walletname=} {zcave=}') + # print(f' - Found one ! {z.walletname=} {zcaveid=}') wallets.add(z) else: wurl = f"/scanupload/{z.walletname.replace('#',':')}" - print(f' - Unrecognised cave name \'{zcave}\' in {z.walletname}') - message = f" ! In {z.walletname} there is an unrecognised cave name '{zcave}'" + print(f' - Unrecognised cave name \'{zcaveid}\' in {z.walletname}') + message = f" ! In {z.walletname} there is an unrecognised cave name '{zcaveid}'" DataIssue.objects.update_or_create(parser='scans', message=message, url=wurl) manywallets = list(set(wallets)) diff --git a/templates/personwallets.html b/templates/personwallets.html index 147f047..255d03e 100644 --- a/templates/personwallets.html +++ b/templates/personwallets.html @@ -30,8 +30,8 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {{wallet.persons}} {% if wallet.cave %} - {% if wallet.cave.slug %} - {{wallet.cave}} + {% if wallet.caveobj.slug %} + {{wallet.cave}} {% else %} {{wallet.cave}} {% endif %} diff --git a/templates/wallet_table.html b/templates/wallet_table.html index b83bb16..1d99f27 100644 --- a/templates/wallet_table.html +++ b/templates/wallet_table.html @@ -24,12 +24,13 @@ {% if wallet.date %}{{wallet.date}}{% else %} {% endif %} {% if wallet.cave %} - {% if wallet.cave.slug %} - {{wallet.cave}} + {% if wallet.caveobj.slug %} + {{wallet.cave}} {% else %} {{wallet.cave}} {% endif %} {% else %} + No wallet.cave {{wallet.cave}} {% endif %} {% if wallet.name %}{{wallet.name}}{% else %}{% if wallet.displaynames %} {% for dn in wallet.displaynames %}{{dn}}{%if not forloop.last %}, {% endif %} {% endfor %}{% else %} {% endif %}{% endif %} diff --git a/templates/yearwallets.html b/templates/yearwallets.html index a6391e3..32545ba 100644 --- a/templates/yearwallets.html +++ b/templates/yearwallets.html @@ -40,8 +40,8 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {{wallet.persons}} {% if wallet.cave %} - {% if wallet.cave.slug %} - {{wallet.cave}} + {% if wallet.caveobj.slug %} + {{wallet.cave}} {% else %} {{wallet.cave}} {% endif %}