mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 10:37:07 +00:00
Make people listed in wallets url-linkable
This commit is contained in:
@@ -43,12 +43,12 @@ def populatewallet(w):
|
||||
Only gets data from the survex file when it was parsed on import, or edited (& thus parsed) online,
|
||||
so doesn't work if there was no *ref value
|
||||
"""
|
||||
slugpeople = []
|
||||
slugpeople = set()
|
||||
blocks = SurvexBlock.objects.filter(scanswallet=w)
|
||||
for b in blocks:
|
||||
for personrole in b.survexpersonrole_set.all():
|
||||
slugpeople.append(personrole.person) # Person objects, not the names anymore
|
||||
w.slugpeople = list(set(slugpeople))
|
||||
slugpeople.add(personrole.person) # Person objects, not the names anymore
|
||||
w.slugpeople = slugpeople
|
||||
|
||||
|
||||
def caveifywallet(w):
|
||||
@@ -80,9 +80,9 @@ def fillblankpeople(w):
|
||||
if no one explicitly attached.
|
||||
the JSON string which may OR MAY NOT be formatted as a list.
|
||||
|
||||
w.slugpeople is set only if there is no explicit string of people's name in the wallet
|
||||
w.persons is set only if there is an explicit list of peoples' names in the wallet
|
||||
The template choses which to display depending on whether w.slugpeople exists or not.
|
||||
w.slugpeople is from the survexfiles
|
||||
w.persons is from the explicit list of peoples' names in the wallet
|
||||
The template choses how to display them.
|
||||
"""
|
||||
def nobody(wplist):
|
||||
if len(wplist) > 1:
|
||||
@@ -94,7 +94,7 @@ def fillblankpeople(w):
|
||||
else:
|
||||
return False
|
||||
|
||||
wp = w.people() # just a list of names as strings, direct from JSON. Replace with list of Person objects in parser?
|
||||
wp = w.people() # just a list of names as strings, direct from JSON.
|
||||
if not isinstance(wp, list): # might be None
|
||||
print(f"{w} NOT A LIST {type(wp)}: {wp}")
|
||||
populatewallet(w)
|
||||
@@ -109,9 +109,13 @@ def fillblankpeople(w):
|
||||
if nobody(wp):
|
||||
populatewallet(w) # sets w.slugpeople
|
||||
else:
|
||||
w.persons = wp
|
||||
w.persons = parse_name_list(w)
|
||||
populatewallet(w) # sets w.slugpeople
|
||||
if hasattr(w, "slugpeople"):
|
||||
w.persons = w.persons.difference(w.slugpeople)
|
||||
return
|
||||
|
||||
|
||||
def is_cave(wallet, id):
|
||||
if not id:
|
||||
return False
|
||||
@@ -162,18 +166,43 @@ def fillblankothers(w):
|
||||
w.caveobj = Gcavelookup[wcaveid.strip("' []'")]
|
||||
|
||||
|
||||
|
||||
|
||||
def fixsurvextick(w, ticks):
|
||||
ticks["S"] = w.fixsurvextick(ticks["S"])
|
||||
|
||||
def parse_name_list(w):
|
||||
"""Given a list of strings, which are names, and the year of an expo,
|
||||
return a set of Persons
|
||||
"""
|
||||
namelist = w.people()
|
||||
peeps = set()
|
||||
expo = Expedition.objects.get(year=w.year())
|
||||
crew = GetPersonExpeditionNameLookup(expo)
|
||||
|
||||
for n in namelist:
|
||||
# if n.lower().startswith("lydia"):
|
||||
# print(f"{w} {n=} ")
|
||||
# for x in crew:
|
||||
# if x.lower()==n.lower():
|
||||
# print(f"{w} {n=} {x=}")
|
||||
|
||||
if n.lower() in crew:
|
||||
peeps.add(crew[n.lower()].person)
|
||||
else:
|
||||
if n.startswith("*"): #ignore people flagged as guests or not-expo anyway, such as ARGE
|
||||
pass
|
||||
nobod = n.lower()
|
||||
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
|
||||
pass
|
||||
else:
|
||||
wurl = f"/walletedit/{w.walletname.replace('#',':')}"
|
||||
message = f"{w} name '{n.lower()}' NOT found in GetPersonExpeditionNameLookup({w.year()}) ?!"
|
||||
print(message)
|
||||
DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl)
|
||||
return peeps
|
||||
|
||||
def walletslistperson(request, slug):
|
||||
"""Page which displays a list of all the wallets for a specific person
|
||||
HORRIBLE linear search through everything. Index and do SQL query properly
|
||||
Currently ONLY getting wallets with survex files attached, not free-text searching the wallet.people list
|
||||
"""
|
||||
# GetPersonExpeditionNameLookup
|
||||
|
||||
# Remember that 'personexpedition__expedition' is interpreted by Django to mean the
|
||||
# 'expedition' object which is connected by a foreign key to the 'personexpedition'
|
||||
@@ -183,29 +212,39 @@ def walletslistperson(request, slug):
|
||||
def personwallet(p):
|
||||
manywallets = set()
|
||||
|
||||
# Get the persons from the survexblocks on the survexfiles attached to the wallet directly
|
||||
sps = SurvexPersonRole.objects.filter(person=p)
|
||||
for sp in sps:
|
||||
w = sp.survexblock.scanswallet
|
||||
if w:
|
||||
manywallets.add(w)
|
||||
|
||||
|
||||
# Now read the text strings in the list of wallet people and identify the person
|
||||
pes = PersonExpedition.objects.filter(person=p)
|
||||
for person_expo in pes:
|
||||
expo = person_expo.expedition
|
||||
year = expo.year
|
||||
|
||||
crew = GetPersonExpeditionNameLookup(expo)
|
||||
wallets = Wallet.objects.filter(walletyear__year=year)
|
||||
for w in wallets:
|
||||
if w in manywallets: # already seen it
|
||||
if w in manywallets:
|
||||
# we already know this is a wallet we need to report on
|
||||
continue
|
||||
w.persons = w.people() # ephemeral attribute 'persons' for web page
|
||||
crew = GetPersonExpeditionNameLookup(expo)
|
||||
for n in w.persons:
|
||||
for n in w.people():
|
||||
# if n.lower().startswith("lydia"):
|
||||
# print(f"{w} {n=} ")
|
||||
# for x in crew:
|
||||
# if x.lower()==n.lower():
|
||||
# print(f"{w} {n=} {x=}")
|
||||
|
||||
if n.lower() in crew:
|
||||
if crew[n.lower()] == person_expo:
|
||||
manywallets.add(w)
|
||||
# print(f"{w} Found a non-survex wallet for {person_expo}")
|
||||
else:
|
||||
if n.startswith("*"): #ignore people flagged as guests or not-expo anyway, such as ARGE
|
||||
pass
|
||||
nobod = n.lower()
|
||||
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
|
||||
pass
|
||||
@@ -337,8 +376,8 @@ def cavewallets(request, 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)
|
||||
# message = f" ! In {z.walletname} cavewallets, ignoring '{cleanid}' as not a cave"
|
||||
# print(message)
|
||||
pass
|
||||
else:
|
||||
wurl = f"/walletedit/{z.walletname.replace('#',':')}"
|
||||
|
||||
Reference in New Issue
Block a user