2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

wallets-per-person now finding non-survex wallets

This commit is contained in:
Philip Sargent 2023-10-04 18:22:54 +03:00
parent 9f4306e367
commit bc621efc36
8 changed files with 119 additions and 61 deletions

View File

@ -701,12 +701,12 @@ def GetCaveLookup():
if ldup:
message = f" - Ambiguous aliases removed: {ldup}"
print(message)
DataIssue.objects.create(parser="aliases ok", message=message)
DataIssue.objects.update_or_create(parser="aliases ok", message=message)
for c in Gcave_count:
if Gcave_count[c] > 1:
message = f" ** Duplicate cave id count={Gcave_count[c]} id:'{Gcavelookup[c]}' cave __str__:'{c}'"
print(message)
DataIssue.objects.create(parser="aliases", message=message)
DataIssue.objects.update_or_create(parser="aliases", message=message)
return Gcavelookup

View File

@ -7,15 +7,14 @@ from django.http import HttpResponse
from django.shortcuts import render
from troggle.core.models.caves import GetCaveLookup
from troggle.core.models.survex import SingleScan, SurvexBlock
from troggle.core.models.survex import SingleScan, SurvexBlock, SurvexPersonRole
from troggle.core.models.wallets import Wallet
from troggle.core.models.troggle import DataIssue, Expedition, Person
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
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
from troggle.parsers.survex import set_walletdate
# from troggle.parsers.people import GetPersonExpeditionNameLookup
# import parsers.surveys
"""one of these views serves files as binary blobs, and simply set the mime type based on the file extension,
as does the urls.py dispatcher which sends them here. Here they should actually have the filetype checked
@ -37,21 +36,21 @@ add this file in to the todo list thinggy.
def populatewallet(w):
"""Copy survex data here just for display, not permanently
Only gets data from the survex file when it was parsed on import..
so doesn't work if there is no *ref value
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
"""
survexpeople = []
slugpeople = []
blocks = SurvexBlock.objects.filter(scanswallet=w)
for b in blocks:
for personrole in b.survexpersonrole_set.all():
survexpeople.append(personrole.personname)
w.persons = list(set(survexpeople))
slugpeople.append(personrole.person) # Person objects, not the names anymore
w.slugpeople = list(set(slugpeople))
def caveifywallet(w):
"""Gets the cave from the list of survex files,
only selects one of them though. Only used for display.
FIX THIS to display many caves
"""
# print(f' - Caveify {w=}')
blocknames = []
@ -73,18 +72,41 @@ def caveifywallet(w):
def fillblankpeople(w):
# this isn't working..? why? Because it needs a *ref and an import
wp = w.people()
w.persons = wp
if not wp:
"""Find people attached to a wallet via the survex files
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.
"""
def nobody(wplist):
if len(wplist) > 1:
return False
nobod = wp[0].lower()
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
return True
else:
return False
wp = w.people() # just a list of names as strings, direct from JSON. Replace with list of Person objects in parser?
if not isinstance(wp, list): # might be None
print(f"{w} NOT A LIST {type(wp)}: {wp}")
populatewallet(w)
return
if not wp: # e.g. empty list
# print(f"{w} {wp=}")
populatewallet(w) # sets w.slugpeople
return
if nobody(wp):
populatewallet(w) # sets w.slugpeople
else:
if len(wp) == 1:
# print(f' - {wp=}')
nobody = wp[0].lower()
if nobody == "unknown" or nobody == "nobody" or nobody == " " or nobody == "":
# print(f' - {wp=} {nobody=}')
populatewallet(w)
w.persons = wp
return
def is_cave(wallet, id):
if not id:
@ -145,41 +167,61 @@ def fixsurvextick(w, ticks):
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
"""
# This is where we face having to re-do everything to do with names properly, rather than the horrible series of hacks over 20 years..
# GetPersonExpeditionNameLookup
def tickspersonwallet(p):
manywallets = []
wallets = Wallet.objects.all()
for w in wallets:
w.persons = w.people() # ephemeral attribute for web page
# Remember that 'personexpedition__expedition' is interpreted by Django to mean the
# 'expedition' object which is connected by a foreign key to the 'personexpedition'
# object, which is a field of the PersonLogEntry object:
# PersonLogEntry.objects.filter(personexpedition__expedition=expo)
def personwallet(p):
manywallets = set()
sps = SurvexPersonRole.objects.filter(person=p)
for sp in sps:
w = sp.survexblock.scanswallet
if w:
manywallets.add(w)
pes = PersonExpedition.objects.filter(person=p)
for person_expo in pes:
expo = person_expo.expedition
year = expo.year
wallets = Wallet.objects.filter(walletyear__year=year)
for w in wallets:
if w in manywallets: # already seen it
continue
w.persons = w.people() # ephemeral attribute 'persons' for web page
crew = GetPersonExpeditionNameLookup(expo)
for n in w.persons:
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:
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}' NOT found with GetPersonExpeditionNameLookup on {year} ?!"
print(message)
DataIssue.objects.update_or_create(parser="scans", message=message, url=wurl)
for w in manywallets:
fillblankpeople(w)
if w.persons:
if p.fullname in w.persons:
manywallets.append(w)
fillblankothers(w)
w.ticks = w.get_ticks() # the complaints in colour form
fixsurvextick(w, w.ticks)
fillblankothers(w)
w.ticks = w.get_ticks() # the complaints in colour form
fixsurvextick(w, w.ticks)
return manywallets
# print("-walletslistperson")
p = Person.objects.get(slug=slug)
# try:
# if last_name:
# p = Person.objects.get(fullname=f"{first_name} {last_name}")
# else:
# # special Wookey-hack
# p = Person.objects.get(first_name=f"{first_name}")
# except:
# # raise
# return render(
# request,
# "errors/generic.html",
# {"message": f'Unrecognised name of a expo person: "{first_name} {last_name}"'},
# )
manywallets = tickspersonwallet(p)
manywallets = personwallet(p)
expeditions = Expedition.objects.all()
print("--")
return render(
@ -269,7 +311,7 @@ def cavewallets(request, caveid):
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}'"
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)
@ -291,12 +333,12 @@ def cavewallets(request, caveid):
# print(f' - Found one ! {z.walletname=} {zcaveid=}')
wallets.add(z)
elif cleanid in ['surface', 'unknown', '']:
message = f" ! In {z.walletname} ignore '{cleanid}' "
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} there is an unrecognised cave name '{cleanid}', adding to pending list."
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}")

View File

@ -170,6 +170,20 @@ def who_is_this(year, possibleid):
return None
def when_on_expo(name):
"""Returns a list of PersonExpedition objects for the string, if recognised as a name
"""
person_expos = []
expos = Expedition.objects.all()
for expo in expos:
expoers = GetPersonExpeditionNameLookup(expo)
if name in expoers:
person_expos.append(expoers[name])
print(f"{name} => {expoers[name]}")
return person_expos
global foreign_friends
foreign_friends = [
"Aiko",
@ -207,7 +221,8 @@ def known_foreigner(id):
# Refactor. The dict GetPersonExpeditionNameLookup(expo) indexes by name and has values of personexpedition
# This is convoluted, the whole personexpedition concept is unnecessary?
# This is convoluted, the personexpedition concept is unnecessary, should it just retunr person??
# Or better, query with a string and return a list of personexpeditions
Gpersonexpeditionnamelookup = {}

View File

@ -30,6 +30,8 @@ def load_all_scans():
It does NOT read or validate anything in the JSON data attached to each wallet. Those checks
are done at runtime, when a wallet is accessed, not at import time.
Loads people as a simple string of fullnames. We should replace this with a list of Person slugs.
"""
print(" - Loading Survey Scans")

View File

@ -153,7 +153,7 @@ def get_team_on_trip(survexblock):
def get_people_on_trip(survexblock):
"""Gets the displayable names of the people on a survexbock trip.
Only used for complete team."""
qpeople = get_team_on_trip(survexblock)
qpeople = get_team_on_trip(survexblock) # qpeople is a Query List
people = []
for p in qpeople:

View File

@ -15,7 +15,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<p>This lists all the files in a wallet, some of which may not be for this specific cave.
<p>See also wallets
<ul><li>per cave, e.g. <a href="/cave/scans/1623-204">1623-204</a>, <a href="/cave/scans/1626-359">1626-359</a>, <a href="/cave/scans/1623-290">1623-290</a>, <a href="/cave/scans/1623-291">1623-291</a>, <a href="/cave/scans/1623-258">1623-258</a>, <a href="/cave/scans/1623-264">1623-264</a>
<li>per person, e.g. <a href="/wallets/person/Wookey">Wookey</a>, <a href="/wallets/person/ChrisDensham">Chris Densham</a>, <a href="/wallets/person/MartinGreen">Martin Green</a>, <a href="/wallets/person/AndrewAtkinson">Andrew Atkinson</a>, <a href="/wallets/person/JulianTodd">Julian Todd</a>, <a href="/wallets/person/Jenny Black">Jenny Black</a> <a href="/wallets/person/FrankTully">Frank Tully</a>, <a href="/wallets/person/DaveLoeffler">Dave Loeffler</a>, <a href="/wallets/person/BeckaLawson">Becka</a>
<li>per person, e.g. <a href="/wallets/person/wookey">Wookey</a>, <a href="/wallets/person/chris-densham">Chris Densham</a>, <a href="/wallets/person/martin-green">Martin Green</a>, <a href="/wallets/person/andrew-atkinson">Andrew Atkinson</a>, <a href="/wallets/person/julian-todd">Julian Todd</a>, <a href="/wallets/person/frank-tully">FrankTully</a>, <a href="/wallets/person/dave-loeffler">Dave Loeffler</a>, <a href="/wallets/person/becka-lawson">Becka</a>
<li>per year:
{% for otherexpedition in expeditions %}
| <a <a href="/wallets/year/{{ otherexpedition.year }}">{{otherexpedition.year}}</a>
@ -31,8 +31,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<td style="padding:2px">{% if wallet.walletdate %}{{wallet.walletdate}}{% else %} {% endif %}</td>
<td style="padding:2px">{% if wallet.name %}{{wallet.name|truncatechars:20}}{% else %}<em>{% if wallet.displaynames %} {% for dn in wallet.displaynames %}{{dn}}{%if not forloop.last %}, {% endif %} {% endfor %}{% else %} {% endif %}</em>{% endif %}</td>
<td style="padding:2px">{{wallet.persons }} </td>
<td style="padding:2px">{% if wallet.slugpeople %}{%for p in wallet.slugpeople%}<a href="/person/{{p.slug}}">{{p.fullname}}</a>{%if not forloop.last %}, {% endif %}{% endfor %}{% else %}{{wallet.persons }}{% endif %}</td>
<td align="center" style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.singlescan_set.all|length}}</a></td>
<td style="padding:2px">
{% for survexblock in wallet.survexblock_set.all %}

View File

@ -30,7 +30,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<td style="padding:2px" >{% if wallet.walletdate %}{{wallet.walletdate}}{% else %} {% endif %}</td>
<td style="padding:2px">{% if wallet.name %}{{wallet.name|truncatechars:20}}{% else %}<em>{% if wallet.displaynames %} {% for dn in wallet.displaynames %}{{dn}}{%if not forloop.last %}, {% endif %} {% endfor %}{% else %} {% endif %}</em>{% endif %}</td>
<td style="padding:2px">{{wallet.persons}}</td>
<td style="padding:2px">{% if wallet.slugpeople %}{%for p in wallet.slugpeople%}<a href="/person/{{p.slug}}">{{p.fullname}}</a>{%if not forloop.last %}, {% endif %}{% endfor %}{% else %}{{wallet.persons }}{% endif %}</td>
<td style="padding:2px">
{% if wallet.cave %}
{% if wallet.caveobj.slug %}

View File

@ -39,7 +39,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<td style="padding:2px">{% if wallet.walletdate %}{{wallet.walletdate}}{% else %} {% endif %}</td>
<td style="padding:2px">{% if wallet.name %}{{wallet.name|truncatechars:20}}{% else %}<em>{% if wallet.displaynames %} {% for dn in wallet.displaynames %}{{dn}}{%if not forloop.last %}, {% endif %} {% endfor %}{% else %} {% endif %}</em>{% endif %}</td>
<td style="padding:2px">{{wallet.persons}}</td>
<td style="padding:2px">{% if wallet.slugpeople %}{%for p in wallet.slugpeople%}<a href="/person/{{p.slug}}">{{p.fullname}}</a>{%if not forloop.last %}, {% endif %}{% endfor %}{% else %}{{wallet.persons }}{% endif %}</td>
<td style="padding:2px">
{% if wallet.cave %}
{% if wallet.caveobj.slug %}