mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 03:37:09 +00:00
wallets per person - slow implementation
This commit is contained in:
@@ -203,18 +203,26 @@ class Wallet(models.Model):
|
||||
|
||||
# Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it
|
||||
def date(self):
|
||||
if not self.get_json():
|
||||
return None
|
||||
jsondata = self.get_json()
|
||||
return jsondata["date"]
|
||||
|
||||
def people(self):
|
||||
if not self.get_json():
|
||||
return None
|
||||
jsondata = self.get_json()
|
||||
return jsondata["people"]
|
||||
|
||||
def cave(self):
|
||||
if not self.get_json():
|
||||
return None
|
||||
jsondata = self.get_json()
|
||||
return jsondata["cave"]
|
||||
|
||||
def name(self):
|
||||
if not self.get_json():
|
||||
return None
|
||||
jsondata = self.get_json()
|
||||
return jsondata["name"]
|
||||
|
||||
|
||||
@@ -124,11 +124,11 @@ class Person(TroggleModel):
|
||||
fullname = models.CharField(max_length=200)
|
||||
is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
|
||||
mug_shot = models.CharField(max_length=100, blank=True,null=True)
|
||||
blurb = models.TextField(blank=True,null=True)
|
||||
blurb = models.TextField(blank=True,null=True)
|
||||
|
||||
#href = models.CharField(max_length=200)
|
||||
orderref = models.CharField(max_length=200) # for alphabetic
|
||||
user = models.OneToOneField(User, null=True, blank=True,on_delete=models.CASCADE)
|
||||
user = models.OneToOneField(User, null=True, blank=True,on_delete=models.CASCADE) # not used now
|
||||
def get_absolute_url(self):
|
||||
return urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
|
||||
|
||||
|
||||
@@ -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