From a2a5e9200ec5a588729a19684bba9c045dad8ef6 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 31 Jul 2022 18:58:46 +0300 Subject: [PATCH] wallets per person - slow implementation --- core/models/survex.py | 8 +++++ core/models/troggle.py | 4 +-- core/views/scans.py | 69 ++++++++++++++++++++++++++++++++---- templates/cavewallets.html | 5 +-- templates/dataissues.html | 2 +- templates/manywallets.html | 1 + templates/personwallets.html | 46 ++++++++++++++++++++++++ templates/yearwallets.html | 9 ++--- urls.py | 3 +- 9 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 templates/personwallets.html diff --git a/core/models/survex.py b/core/models/survex.py index a84a37e..a562a44 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -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"] diff --git a/core/models/troggle.py b/core/models/troggle.py index 593bd1d..84f1bc3 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -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})) diff --git a/core/views/scans.py b/core/views/scans.py index 6ecae2b..d7c48e2 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -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() diff --git a/templates/cavewallets.html b/templates/cavewallets.html index 3208927..8fd5d83 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -13,17 +13,18 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c

See also wallets

- + {% for wallet in manywallets|dictsort:"walletname" %} - +
WalletWallet DateWallet NamePeopleScansSurvex blocksDrawings using these scans
WalletWallet DateWallet NamePeopleScansSurvex blocksDrawings using these scans
{{wallet.walletname}} {{wallet.date}} {{wallet.name}}{{wallet.people}}{{wallet.persons}} {{wallet.singlescan_set.all|length}} diff --git a/templates/dataissues.html b/templates/dataissues.html index 2127a0e..97c415e 100644 --- a/templates/dataissues.html +++ b/templates/dataissues.html @@ -6,7 +6,7 @@

Loading data from files: Issues arising that need attention

-This is work in progress (June 2022).The URL links to the offending objects are enabled on only some types of fault as yet. +This is work in progress.The URL links to the offending objects are enabled on only some types of fault as yet.

See the Data Management To Do list as well as these import/parsing issues. diff --git a/templates/manywallets.html b/templates/manywallets.html index 44d097f..7295ac5 100644 --- a/templates/manywallets.html +++ b/templates/manywallets.html @@ -13,6 +13,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c