mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 10:37:07 +00:00
wallets per person - slow implementation
This commit is contained in:
@@ -10,8 +10,11 @@ from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
|
||||
from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock
|
||||
from troggle.core.models.troggle import Person
|
||||
from troggle.core.models.caves import GetCaveLookup
|
||||
from troggle.core.views.expo import getmimetype
|
||||
#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,
|
||||
@@ -41,15 +44,20 @@ def populatewallet(w):
|
||||
for b in blocks:
|
||||
for personrole in b.survexpersonrole_set.all():
|
||||
survexpeople.append(personrole.personname)
|
||||
w.people = list(set(survexpeople)) # remove duplicates
|
||||
w.persons = list(set(survexpeople))
|
||||
|
||||
def datewallet(w, earliest):
|
||||
first = earliest
|
||||
blocks = SurvexBlock.objects.filter(scanswallet = w)
|
||||
for b in blocks:
|
||||
if b.date:
|
||||
if b.date < earliest:
|
||||
earliest = b.date
|
||||
w.date = earliest
|
||||
if b.date < first:
|
||||
first = b.date
|
||||
if first == earliest:
|
||||
# no date found
|
||||
w.date = None
|
||||
else:
|
||||
w.date = first
|
||||
|
||||
def caveifywallet(w):
|
||||
blocks = SurvexBlock.objects.filter(scanswallet = w)
|
||||
@@ -57,11 +65,59 @@ def caveifywallet(w):
|
||||
# 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
|
||||
print(w.cave)
|
||||
|
||||
def walletslistperson(request, first_name, last_name):
|
||||
'''Page which displays a list of all the wallets for a specific person
|
||||
HORRIBLE linear search through everything. Index and do SQL query properly
|
||||
'''
|
||||
# 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
|
||||
|
||||
try:
|
||||
if last_name:
|
||||
p = Person.objects.get(fullname= f'{first_name} {last_name}')
|
||||
else:
|
||||
# speciall 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}"'})
|
||||
|
||||
#personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower())
|
||||
earliest = datetime.datetime.now().date()
|
||||
|
||||
manywallets = []
|
||||
wallets = Wallet.objects.all()
|
||||
for w in wallets:
|
||||
w.persons = w.people() # ephemeral attribute for web page
|
||||
# check if there is a json
|
||||
if not w.get_json():
|
||||
populatewallet(w)
|
||||
else:
|
||||
wp = w.people()
|
||||
if not wp: # an -empty list
|
||||
populatewallet(w)
|
||||
else:
|
||||
if len(wp) == 1:
|
||||
nobody = wp[0].lower()
|
||||
if nobody == 'unknown' or nobody == 'nobody' or nobody == ' ':
|
||||
populatewallet(w)
|
||||
|
||||
if p.fullname in w.persons:
|
||||
#found person
|
||||
manywallets.append(w)
|
||||
|
||||
if not w.date():
|
||||
datewallet(w, earliest)
|
||||
|
||||
c = w.cave()
|
||||
if not c:
|
||||
caveifywallet(w)
|
||||
|
||||
return render(request, 'personwallets.html', { 'manywallets':manywallets, 'settings': settings, 'person': p})
|
||||
|
||||
def walletslistyear(request, year):
|
||||
'''Page which displays a list of all the wallets in a specific year - TO BE WRITTEN
|
||||
'''Page which displays a list of all the wallets in a specific year
|
||||
'''
|
||||
if year < 1976 or year > 2050:
|
||||
return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'})
|
||||
@@ -78,7 +134,6 @@ def walletslistyear(request, year):
|
||||
print(w.year(), w)
|
||||
manywallets.append(w)
|
||||
else:
|
||||
print("NOT WANTED",year, w.year())
|
||||
continue
|
||||
|
||||
wp = w.people()
|
||||
|
||||
Reference in New Issue
Block a user