detecting orphan cave ids and adding to pending list

This commit is contained in:
2023-08-02 18:23:04 +03:00
parent c76c09fced
commit a0f85454f8
3 changed files with 110 additions and 37 deletions

View File

@@ -12,6 +12,7 @@ from troggle.core.models.wallets import Wallet
from troggle.core.models.troggle import DataIssue, Expedition, Person
from troggle.core.views.expo import getmimetype
from troggle.parsers.survex import set_walletdate
from troggle.parsers.caves import add_cave_to_pending_list
# from troggle.parsers.people import GetPersonExpeditionNameLookup
# import parsers.surveys
@@ -85,8 +86,21 @@ def fillblankpeople(w):
# print(f' - {wp=} {nobody=}')
populatewallet(w)
def is_cave(id):
Gcavelookup = GetCaveLookup()
id = id.strip("' []'")
if id in Gcavelookup:
return True
else:
print(f" - Failed to find cave object from id <{id}>")
if id.lower() != "unknown" and id != "":
print(f" - adding <{id}> to pendingcaves.txt list")
add_cave_to_pending_list(id)
return False
def fillblankothers(w):
"""This is on the way to having a many:many relationship between Caves and Wallets
"""
if not w.walletdate:
set_walletdate(w)
@@ -98,14 +112,21 @@ def fillblankothers(w):
else:
if type(wcaveid) == list:
for i in wcaveid:
if i in Gcavelookup:
w.caveobj = Gcavelookup[i] # just sets it to the last one found. nasty. bug waiting to happen
# print(f' - Found cave object from id {wcaveid}')
i = i.strip("' []'")
if is_cave(i):
w.caveobj = Gcavelookup[i] # just sets it to the last one found. nasty. bug waiting to happen
elif wcaveid.find(',') != -1:
# it's a list of cave ids as a string
ids = wcaveid.split(',')
for i in ids:
i = i.strip("' []'")
if is_cave(i):
w.caveobj = Gcavelookup[i] # just sets it to the last one found. nasty. bug waiting to happen
else:
if wcaveid in Gcavelookup:
w.caveobj = Gcavelookup[wcaveid]
else:
print(f" - Failed to find cave object from id {wcaveid}")
if is_cave(wcaveid):
w.caveobj = Gcavelookup[wcaveid.strip("' []'")]
def fixsurvextick(w, ticks):
@@ -216,7 +237,7 @@ def walletslistyear(request, year):
def cavewallets(request, caveid):
"""Returns all the wallets for just one cave"""
print("-cavewalletsl")
print("-cavewallets")
Gcavelookup = GetCaveLookup()
if caveid in Gcavelookup:
@@ -233,8 +254,23 @@ def cavewallets(request, caveid):
for z in zilchwallets:
zcaveid = z.cave()
if zcaveid:
cleanid = str(zcaveid).strip("'[]'")
if cleanid in Gcavelookup:
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} 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(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=}')
@@ -245,9 +281,10 @@ def cavewallets(request, caveid):
pass
else:
wurl = f"/walletedit/{z.walletname.replace('#',':')}"
message = f" ! In {z.walletname} there is an unrecognised cave name '{cleanid}' (out of {len(Gcavelookup):,} cave names and aliases)"
message = f" ! In {z.walletname} 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)
manywallets = list(set(wallets))
for w in manywallets:
@@ -277,7 +314,8 @@ def oldwallet(request, path):
def scansingle(request, path, file):
"""sends a single binary file to the user for display - browser decides how using mimetype"""
"""sends a single binary file to the user for display - browser decides how using mimetype
This is very unsafe"""
try:
wallet = Wallet.objects.get(walletname=urlunquote(path))
singlescan = SingleScan.objects.get(wallet=wallet, name=file)