diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-10-21 22:31:33 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-10-21 22:31:33 +0300 |
commit | 1641dfe5f199e26607e8367395f4f8aa04eb376b (patch) | |
tree | efed94787898f8d395c8a1e8113a369bdd60b0e7 /core/views | |
parent | e7a0c57330a9c3808531b4d401d0cedf0f0c0638 (diff) | |
download | troggle-1641dfe5f199e26607e8367395f4f8aa04eb376b.tar.gz troggle-1641dfe5f199e26607e8367395f4f8aa04eb376b.tar.bz2 troggle-1641dfe5f199e26607e8367395f4f8aa04eb376b.zip |
tidy with new multicave wallets
Diffstat (limited to 'core/views')
-rw-r--r-- | core/views/scans.py | 95 | ||||
-rw-r--r-- | core/views/wallets_edit.py | 9 |
2 files changed, 57 insertions, 47 deletions
diff --git a/core/views/scans.py b/core/views/scans.py index 4d9f851..7cb0b94 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -128,7 +128,7 @@ def is_cave(wallet, id): print(f" - Wallet {wallet} Failed to find cave object from id <{id}>") if id.lower() != "unknown" and id != "": print(f" - adding <{id}> to pendingcaves DataIssues") - add_cave_to_pending_list(id, wallet, f"Wallet {wallet} - Could not find id <{id}>") + add_cave_to_pending_list(id, wallet, f"Wallet {wallet} - Could not find cave id <{id}>") return False def fillblankothers(w): @@ -260,11 +260,15 @@ def walletslistperson(request, slug): manywallets = personwallet(p) expeditions = Expedition.objects.all() - print("--") + length_ug = 0.0 + for w in manywallets: + for sb in w.survexblock_set.all(): + length_ug += sb.legslength return render( request, "personwallets.html", - {"manywallets": manywallets, "settings": settings, "person": p, "expeditions": expeditions}, + {"manywallets": manywallets, "settings": settings, "person": p, "expeditions": expeditions, + "length_ug": length_ug} ) @@ -309,7 +313,6 @@ def walletslistyear(request, year): for w in manywallets: for sb in w.survexblock_set.all(): length_ug += sb.legslength - print("--") return render( request, "yearwallets.html", @@ -336,50 +339,52 @@ def cavewallets(request, caveid): # 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)) + # 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() - if zcaveid: - cleanid = str(zcaveid).strip("' []'") + # 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) + # 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 + # # 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" + # 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) - 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}") + # 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)) for w in manywallets: fillblankpeople(w) @@ -387,11 +392,15 @@ def cavewallets(request, caveid): w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc fixsurvextick(w, w.ticks) expeditions = Expedition.objects.all() - print("--") + length_ug = 0.0 + for w in manywallets: + for sb in w.survexblock_set.all(): + length_ug += sb.legslength return render( request, "cavewallets.html", - {"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions}, + {"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions, + "length_ug": length_ug} ) diff --git a/core/views/wallets_edit.py b/core/views/wallets_edit.py index a9022f3..c99201b 100644 --- a/core/views/wallets_edit.py +++ b/core/views/wallets_edit.py @@ -244,7 +244,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): w.caves.add(caveobject) # new many-to-many field #print(w.caves) else: - # either single cave or the square barckets have been removed + # either single cave or the square brackets have been removed ids = caveid.split(",") for i in ids: j = i.replace("'","").strip('[] "') @@ -254,7 +254,6 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): w.caves.add(caveobject) except: pass - print(f'get_cave_leniently from "{waldata["cave"]}" => {caveobject}') # if not caveobject.url == waldata["description url"]: # complaints.append(f'The URL of cave description \"{waldata["description url"]}\" does not match the one on record for this cave which is: "{caveobject.url}". If the wallet is not for a cave, put a useful URL here.') except Cave.MultipleObjectsReturned: @@ -573,7 +572,9 @@ def walletedit(request, path=None): svxf = svxf.with_suffix(".svx") f = Path(settings.SURVEX_DATA) / svxf if not f.is_file(): - message = f"Specified survex file '{fpath}' in database not found on disc" + message = f"! {wallet} Specified survex file '{svxf}' in wallet not found on disc, probably renamed." + DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) # set URL to this wallet folder + print(message) continue @@ -582,7 +583,7 @@ def walletedit(request, path=None): try: svxfile = SurvexFile.objects.get(path=fpath) except: - message = f"Specified survex file '{fpath}'not found? database may be empty. Exception." + message = f"Specified and present survex file '{fpath}'not found in db. Database may be empty. Exception." print(message) # This failure will also get picked up by the "S" colour code red or orange try: |