wallets per person - slow implementation

This commit is contained in:
Philip Sargent 2022-07-31 18:58:46 +03:00
parent c1ba6a39a5
commit a2a5e9200e
9 changed files with 130 additions and 17 deletions

View File

@ -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 # Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it
def date(self): def date(self):
if not self.get_json():
return None
jsondata = self.get_json() jsondata = self.get_json()
return jsondata["date"] return jsondata["date"]
def people(self): def people(self):
if not self.get_json():
return None
jsondata = self.get_json() jsondata = self.get_json()
return jsondata["people"] return jsondata["people"]
def cave(self): def cave(self):
if not self.get_json():
return None
jsondata = self.get_json() jsondata = self.get_json()
return jsondata["cave"] return jsondata["cave"]
def name(self): def name(self):
if not self.get_json():
return None
jsondata = self.get_json() jsondata = self.get_json()
return jsondata["name"] return jsondata["name"]

View File

@ -124,11 +124,11 @@ class Person(TroggleModel):
fullname = models.CharField(max_length=200) 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) 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) 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) #href = models.CharField(max_length=200)
orderref = models.CharField(max_length=200) # for alphabetic 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): def get_absolute_url(self):
return urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name})) return urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))

View File

@ -10,8 +10,11 @@ from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock 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.models.caves import GetCaveLookup
from troggle.core.views.expo import getmimetype from troggle.core.views.expo import getmimetype
#from troggle.parsers.people import GetPersonExpeditionNameLookup
#import parsers.surveys #import parsers.surveys
'''one of these views serves files as binary blobs, and simply set the mime type based on the file extension, '''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 b in blocks:
for personrole in b.survexpersonrole_set.all(): for personrole in b.survexpersonrole_set.all():
survexpeople.append(personrole.personname) survexpeople.append(personrole.personname)
w.people = list(set(survexpeople)) # remove duplicates w.persons = list(set(survexpeople))
def datewallet(w, earliest): def datewallet(w, earliest):
first = earliest
blocks = SurvexBlock.objects.filter(scanswallet = w) blocks = SurvexBlock.objects.filter(scanswallet = w)
for b in blocks: for b in blocks:
if b.date: if b.date:
if b.date < earliest: if b.date < first:
earliest = b.date first = b.date
w.date = earliest if first == earliest:
# no date found
w.date = None
else:
w.date = first
def caveifywallet(w): def caveifywallet(w):
blocks = SurvexBlock.objects.filter(scanswallet = 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 # NB b.cave is not populated by parser. Use b.survexfile.cave instead, or we could parse b.survexpath
if b.survexfile.cave: if b.survexfile.cave:
w.cave = b.survexfile.cave # just gets the last one, randomly 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): 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: if year < 1976 or year > 2050:
return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 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) print(w.year(), w)
manywallets.append(w) manywallets.append(w)
else: else:
print("NOT WANTED",year, w.year())
continue continue
wp = w.people() wp = w.people()

View File

@ -13,17 +13,18 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<p>See also wallets <p>See also wallets
<ul> <ul>
<li>per year, e.g. <a href="/wallets/year/2019">2019</a> <li>per year, e.g. <a href="/wallets/year/2019">2019</a>
<li>per person, e.g. <a href="/wallets/person/MichaelSargent">Michael Sargent</a>
</ul> </ul>
<table width=95%> <table width=95%>
<tr><th>Wallet</th><th>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr> <tr><th>Wallet</th><th width=8%>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr>
{% for wallet in manywallets|dictsort:"walletname" %} {% for wallet in manywallets|dictsort:"walletname" %}
<tr> <tr>
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td> <td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
<td style="padding:2px">{{wallet.date}}</td> <td style="padding:2px">{{wallet.date}}</td>
<td style="padding:2px">{{wallet.name}}</td> <td style="padding:2px">{{wallet.name}}</td>
<td style="padding:2px">{{wallet.people}}</td> <td style="padding:2px">{{wallet.persons}}</td>
<td align="center" style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.singlescan_set.all|length}}</a></td> <td align="center" style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.singlescan_set.all|length}}</a></td>
<td style="padding:2px"> <td style="padding:2px">

View File

@ -6,7 +6,7 @@
<h1>Loading data from files: Issues arising that need attention</h1> <h1>Loading data from files: Issues arising that need attention</h1>
<p> <p>
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.
<p> <p>
See the See the
<a href="/handbook/computing/todo-data.html">Data Management To Do list</a> as well as these import/parsing issues. <a href="/handbook/computing/todo-data.html">Data Management To Do list</a> as well as these import/parsing issues.

View File

@ -13,6 +13,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
<ul> <ul>
<li>per year, e.g. <a href="/wallets/year/2019">2019</a> <li>per year, e.g. <a href="/wallets/year/2019">2019</a>
<li>per cave, e.g. <a href="/cave/scans/1623-204">1623/204</a> <li>per cave, e.g. <a href="/cave/scans/1623-204">1623/204</a>
<li>per person, e.g. <a href="/wallets/person/MichaelSargent">Michael Sargent</a>
</ul> </ul>
<!-- This should all be restructured to use .prefetch_related() and .select_related() <!-- This should all be restructured to use .prefetch_related() and .select_related()

View File

@ -0,0 +1,46 @@
{% extends "base.html" %}
{% block title %}One Person Survey scans folders (wallets){% endblock %}
{% block content %}
<h3>Wallets for <a href="{{person.get_absolute_url}}">{{person}}</a> </h3>
<p>Each wallet contains the scanned original in-cave survey notes and sketches of
plans and elevations. It also contains scans of centre-line survex output on which
hand-drawn passage sections are drawn. These hand-drawn passages will eventually be
traced to produce Tunnel or Therion drawings and eventually the final complete cave survey.
<p>See also wallets
<ul>
<li>per year, e.g. <a href="/wallets/year/2019">2019</a>
<li>per cave, e.g. <a href="/cave/scans/1623-161">1623/161</a>
</ul>
<table width=95%>
<tr><th>Wallet</th><th width=8%>Wallet Date</th><th>Wallet Name</th><th width=15%>Other People</th><th>Cave</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr>
{% for wallet in manywallets|dictsort:"walletname" %}
<tr>
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
<td style="padding:2px" >{{wallet.date}}</td>
<td style="padding:2px">{{wallet.name}}</td>
<td style="padding:2px">{{wallet.persons}}</td>
<td style="padding:2px">{{wallet.cave}}</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 %}
<a href="{% url "svx" survexblock.survexfile.path %}">{{survexblock}}</a>
{% endfor %}
</td>
<td style="padding:2px">
{% for drawing in wallet.drawingfile_set.all %}
<a href="{% url "dwgfilesingle" drawing.dwgpath %}">{{drawing.dwgpath}}</a><br>
{% empty %}
(no Tunnel drawings found: but there might be Therion drawings)
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -8,20 +8,21 @@
plans and elevations. It also contains scans of centre-line survex output on which plans and elevations. It also contains scans of centre-line survex output on which
hand-drawn passage sections are drawn. These hand-drawn passages will eventually be hand-drawn passage sections are drawn. These hand-drawn passages will eventually be
traced to produce Tunnel or Therion drawings and eventually the final complete cave survey. traced to produce Tunnel or Therion drawings and eventually the final complete cave survey.
<p>This lists all the files in a wallet, some of which may not be for this specific cave.
<p>See also wallets <p>See also wallets
<ul> <ul>
<li>per cave, e.g. <a href="/cave/scans/1623-204">1623/204</a> <li>per cave, e.g. <a href="/cave/scans/1623-161">1623/161</a>
<li>per person, e.g. <a href="/wallets/person/MichaelSargent">Michael Sargent</a>
</ul> </ul>
<table width=95%> <table width=95%>
<tr><th>Wallet</th><th>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Cave</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr> <tr><th>Wallet</th><th width=8%>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Cave</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr>
{% for wallet in manywallets|dictsort:"walletname" %} {% for wallet in manywallets|dictsort:"walletname" %}
<tr> <tr>
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td> <td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
<td style="padding:2px">{{wallet.date}}</td> <td style="padding:2px">{{wallet.date}}</td>
<td style="padding:2px">{{wallet.name}}</td> <td style="padding:2px">{{wallet.name}}</td>
<td style="padding:2px">{{wallet.people}}</td> <td style="padding:2px">{{wallet.persons}}</td>
<td style="padding:2px">{{wallet.cave}}</td> <td style="padding:2px">{{wallet.cave}}</td>
<td align="center" style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.singlescan_set.all|length}}</a></td> <td align="center" style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.singlescan_set.all|length}}</a></td>

View File

@ -8,7 +8,7 @@ from django.contrib import auth
from django.urls import path, reverse, resolve from django.urls import path, reverse, resolve
from troggle.core.views import statistics, survex from troggle.core.views import statistics, survex
from troggle.core.views.scans import scansingle, allscans, cavewallets, walletslistyear from troggle.core.views.scans import scansingle, allscans, cavewallets, walletslistyear, walletslistperson
from troggle.core.views.drawings import dwgallfiles, dwgfilesingle from troggle.core.views.drawings import dwgallfiles, dwgfilesingle
from troggle.core.views.uploads import dwgupload, scanupload, photoupload from troggle.core.views.uploads import dwgupload, scanupload, photoupload
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage
@ -172,6 +172,7 @@ trogglepatterns = [
# The data about the wallets themselves, not the scans inside tehm # The data about the wallets themselves, not the scans inside tehm
path('wallets/year/<int:year>', walletslistyear, name="walletslistyear"), # wallets that are for a specific year, as an integer '1985' path('wallets/year/<int:year>', walletslistyear, name="walletslistyear"), # wallets that are for a specific year, as an integer '1985'
re_path('wallets/person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)/?', walletslistperson, name="walletslistperson"),
# The tunnel and therion drawings files pageswalletslistcave # The tunnel and therion drawings files pageswalletslistcave