diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2022-07-31 18:58:46 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2022-07-31 18:58:46 +0300 |
commit | a2a5e9200ec5a588729a19684bba9c045dad8ef6 (patch) | |
tree | 8775903f730ca74795b447d16d79bc3ff8460065 | |
parent | c1ba6a39a5f556d832da22e1f8e8ab33494f755b (diff) | |
download | troggle-a2a5e9200ec5a588729a19684bba9c045dad8ef6.tar.gz troggle-a2a5e9200ec5a588729a19684bba9c045dad8ef6.tar.bz2 troggle-a2a5e9200ec5a588729a19684bba9c045dad8ef6.zip |
wallets per person - slow implementation
-rw-r--r-- | core/models/survex.py | 8 | ||||
-rw-r--r-- | core/models/troggle.py | 4 | ||||
-rw-r--r-- | core/views/scans.py | 69 | ||||
-rw-r--r-- | templates/cavewallets.html | 5 | ||||
-rw-r--r-- | templates/dataissues.html | 2 | ||||
-rw-r--r-- | templates/manywallets.html | 1 | ||||
-rw-r--r-- | templates/personwallets.html | 46 | ||||
-rw-r--r-- | templates/yearwallets.html | 9 | ||||
-rw-r--r-- | urls.py | 3 |
9 files changed, 130 insertions, 17 deletions
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 <p>See also wallets <ul> <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> <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" %} <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.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 style="padding:2px"> 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 @@ <h1>Loading data from files: Issues arising that need attention</h1> <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> See the <a href="/handbook/computing/todo-data.html">Data Management To Do list</a> 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 <ul> <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 person, e.g. <a href="/wallets/person/MichaelSargent">Michael Sargent</a> </ul> <!-- This should all be restructured to use .prefetch_related() and .select_related() diff --git a/templates/personwallets.html b/templates/personwallets.html new file mode 100644 index 0000000..27c6db8 --- /dev/null +++ b/templates/personwallets.html @@ -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 %}
\ No newline at end of file diff --git a/templates/yearwallets.html b/templates/yearwallets.html index 87843d2..ce061c0 100644 --- a/templates/yearwallets.html +++ b/templates/yearwallets.html @@ -8,20 +8,21 @@ 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>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> +<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> <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" %} <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.people}}</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> @@ -8,7 +8,7 @@ from django.contrib import auth from django.urls import path, reverse, resolve 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.uploads import dwgupload, scanupload, photoupload 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 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 |