From c39fb3070789c19b870603434560e523166abad4 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 27 Jul 2022 23:22:46 +0300 Subject: new urls and dummy functions and rename --- core/views/scans.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'core/views/scans.py') diff --git a/core/views/scans.py b/core/views/scans.py index 770b925..61d988e 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -20,7 +20,26 @@ by looking inside the file before being served. need to check if inavlid query string is invalid, or produces multiple replies and render a user-friendly error page. ''' - + + +def walletslistyear(request, year): + '''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'}) + else: + year = str(year) + return render(request, 'errors/generic.html', {'message': 'not implemented yet'}) + +def walletslistcave(request, caveid): + '''Page which displays a list of all the wallets attached to a specific cave, e.g. '1623-204' + ''' + g = GetCaveLookup() + if caveid not in g: + return render(request, 'errors/generic.html', {'message': f'Cave identifier not recognised:"{caveid}"'}) + + return render(request, 'errors/generic.html', {'message': 'not implemented yet'}) + def oldwallet(request, path): '''Now called only for non-standard wallet structures for pre-2000 wallets ''' @@ -59,7 +78,7 @@ def scansingle(request, path, file): return render(request, 'errors/generic.html', {'message': message}) -def allwallets(request): +def allscans(request): '''Returns all the wallets in the system, we would like to use the Django queryset SQL optimisation https://docs.djangoproject.com/en/3.2/ref/models/querysets/#prefetch-related to get the related singlescan and survexblock objects but that requires rewriting this to do the query on those, not on -- cgit v1.2.3 From fea69c03717d700192d7a5a5afc4c27a654a923f Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 28 Jul 2022 01:48:22 +0300 Subject: Extend wallets by cave report --- core/models/caves.py | 10 ++++++++-- core/models/survex.py | 34 ++++++++++++++++++++++++++++++++-- core/utils.py | 4 ++++ core/views/scans.py | 40 ++++++++++++++++------------------------ core/views/uploads.py | 2 +- parsers/drawings.py | 2 +- templates/cavewallets.html | 31 ++++++++++++++++++++----------- templates/dwgfiles.html | 2 +- urls.py | 3 +-- 9 files changed, 84 insertions(+), 44 deletions(-) (limited to 'core/views/scans.py') diff --git a/core/models/caves.py b/core/models/caves.py index 8cd658c..f5ae320 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -26,6 +26,14 @@ from django.shortcuts import render from troggle.core.models.troggle import TroggleModel, Person, Expedition, DataIssue from troggle.core.models.survex import SurvexStation from troggle.core.utils import writetrogglefile +from troggle.core.utils import TROG + +# Us ethe TROG global object to cache teh cave lookup list +Gcavelookup = TROG['caves']['gcavelookup'] +Gcave_count = TROG['caves']['gcavecount'] + +Gcavelookup = None +Gcave_count = None '''The model declarations for Areas, Caves and Entrances. Also LogBookENtry, QM, PersonTrip ''' @@ -564,8 +572,6 @@ class PersonTrip(TroggleModel): return f'{self.personexpedition} ({self.logbook_entry.date})' -Gcavelookup = None -Gcave_count = None def GetCaveLookup(): """A very relaxed way of finding probably the right cave given almost any string which might serve to identify it diff --git a/core/models/survex.py b/core/models/survex.py index 1273a8b..9746afb 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -1,6 +1,8 @@ import os -from urllib.parse import urljoin import re +import json +from urllib.parse import urljoin +from pathlib import Path from django.db import models from django.conf import settings @@ -160,6 +162,9 @@ class SurvexPersonRole(models.Model): return str(self.person) + " - " + str(self.survexblock) class Wallet(models.Model): + '''We do not keep the JSON values in the database, we query them afresh each time, + but we will change this when we need to do a Django query on e.g. personame + ''' fpath = models.CharField(max_length=200) walletname = models.CharField(max_length=200) @@ -169,6 +174,31 @@ class Wallet(models.Model): def get_absolute_url(self): return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)})) + def get_json(self): + jsonfile = Path(self.fpath, 'contents.json') + if not Path(jsonfile).is_file(): + print(f'{jsonfile} is not a file') + return None + else: + with open(jsonfile) as json_f: + try: + waldata = json.load(json_f) + except: + wurl = f"/scanupload/{self.walletname}" # .replace('#', ':') + message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file" + print(message) + raise + + return waldata + + def date(self): + jsondata = self.get_json() + return jsondata["date"] + + def name(self): + jsondata = self.get_json() + return jsondata["name"] + def __str__(self): return str(self.walletname) + " (Wallet)" @@ -189,7 +219,7 @@ class SingleScan(models.Model): class DrawingFile(models.Model): dwgpath = models.CharField(max_length=200) dwgname = models.CharField(max_length=200) - manywallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files + dwgwallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files dwgcontains = models.ManyToManyField("DrawingFile") # case when its a frame type filesize = models.IntegerField(default=0) diff --git a/core/utils.py b/core/utils.py index 9aa4679..5b696dd 100644 --- a/core/utils.py +++ b/core/utils.py @@ -42,6 +42,10 @@ TROG = { }, 'issues' : { 'logdataissues' : {} + }, + 'caves' : { + 'gcavelookup' : {}, + 'gcavecount' : {} } } diff --git a/core/views/scans.py b/core/views/scans.py index 61d988e..7d933c7 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -29,16 +29,23 @@ def walletslistyear(request, year): return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'}) else: year = str(year) - return render(request, 'errors/generic.html', {'message': 'not implemented yet'}) + return render(request, 'errors/generic.html', {'message': 'This page logic not implemented yet'}) -def walletslistcave(request, caveid): - '''Page which displays a list of all the wallets attached to a specific cave, e.g. '1623-204' + +def cavewallets(request, caveid): + '''Returns all the wallets for just one cave ''' - g = GetCaveLookup() - if caveid not in g: - return render(request, 'errors/generic.html', {'message': f'Cave identifier not recognised:"{caveid}"'}) - - return render(request, 'errors/generic.html', {'message': 'not implemented yet'}) + Gcavelookup = GetCaveLookup() + if caveid in Gcavelookup: + cave = Gcavelookup[caveid] + else: + return render(request,'errors/badslug.html', {'badslug': caveid}) + + # remove duplication. SOrting is done in the template + wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) # NB a filtered set + manywallets = list(wallets) + + return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave}) def oldwallet(request, path): '''Now called only for non-standard wallet structures for pre-2000 wallets @@ -84,22 +91,7 @@ def allscans(request): to get the related singlescan and survexblock objects but that requires rewriting this to do the query on those, not on the wallets ''' - manywallets = Wallet.objects.all() + manywallets = Wallet.objects.all() # NB all of them # manywallets = Wallet.objects.all().prefetch_related('singlescan') fails as the link is defined on 'singlescan' not on 'wallet' return render(request, 'manywallets.html', { 'manywallets':manywallets, 'settings': settings }) -def cavewallets(request, cave_id): - '''Returns all the wallets for just one cave, - ''' - - Gcavelookup = GetCaveLookup() - if cave_id in Gcavelookup: - cave = Gcavelookup[cave_id] - else: - return render(request,'errors/badslug.html', {'badslug': cave_id}) - - # remove duplication. SOrting is done in the template - wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) - manywallets = list(wallets) - - return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave}) diff --git a/core/views/uploads.py b/core/views/uploads.py index b275d2a..62ed56e 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -93,7 +93,7 @@ xlate = {"url": "description url", "electronic": "electronic survey", "pland": "plan drawn", "elevd": "elev drawn", - "psg": "name", + "psg": "name", # not real ? "survex": "survex file", } diff --git a/parsers/drawings.py b/parsers/drawings.py index 88a6ca3..4b3e44d 100644 --- a/parsers/drawings.py +++ b/parsers/drawings.py @@ -50,7 +50,7 @@ def find_dwg_file(dwgfile, path): scansfile = scansfilel[0] if wallet: - dwgfile.manywallets.add(wallet) + dwgfile.dwgwallets.add(wallet) if scansfile: dwgfile.scans.add(scansfile) diff --git a/templates/cavewallets.html b/templates/cavewallets.html index 2cbce29..509ca9f 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -4,29 +4,38 @@ {% block content %} -

Survey scans folders (wallets) for {{cave}}

+

Wallets for {{cave}} {{cave.official_name|safe}}

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. +

This lists all the files in a wallet, some of which may not be for this specific cave. - -{% for scanswallet in manywallets|dictsort:"walletname" %} + +{% for wallet in manywallets|dictsort:"walletname" %} - - + + + + + + + diff --git a/templates/dwgfiles.html b/templates/dwgfiles.html index 6367ad2..48f236d 100644 --- a/templates/dwgfiles.html +++ b/templates/dwgfiles.html @@ -13,7 +13,7 @@ diff --git a/urls.py b/urls.py index 7dba6f6..d43ac7e 100644 --- a/urls.py +++ b/urls.py @@ -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, walletslistcave +from troggle.core.views.scans import scansingle, allscans, cavewallets, walletslistyear 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 @@ -171,7 +171,6 @@ trogglepatterns = [ path('cave/scans/', cavewallets, name="cavewallets"), # like allscans, but for just one cave # The data about the wallets themselves, not the scans inside tehm - path('wallets/cave/', walletslistcave, name="walletslistcave"), # wallets that are for a specific cave, an identifier path('wallets/year/', walletslistyear, name="walletslistyear"), # wallets that are for a specific year, as an integer '1985' -- cgit v1.2.3 From 724234949f1770645b0f8c34221ae16b0615daf3 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 29 Jul 2022 20:55:19 +0300 Subject: Populate blank wallet fields with survex data --- core/models/survex.py | 7 +++++- core/views/scans.py | 63 +++++++++++++++++++++++++++++++++++++++++++--- templates/cavewallets.html | 9 +++---- 3 files changed, 69 insertions(+), 10 deletions(-) (limited to 'core/views/scans.py') diff --git a/core/models/survex.py b/core/models/survex.py index d8a5fb5..79a645e 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -191,6 +191,7 @@ class Wallet(models.Model): return waldata + # Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it def date(self): jsondata = self.get_json() return jsondata["date"] @@ -199,12 +200,16 @@ class Wallet(models.Model): jsondata = self.get_json() return jsondata["people"] + def cave(self): + jsondata = self.get_json() + return jsondata["cave"] + def name(self): jsondata = self.get_json() return jsondata["name"] def __str__(self): - return str(self.walletname) + " (Wallet)" + return "[" + str(self.walletname) + " (Wallet)]" class SingleScan(models.Model): ffile = models.CharField(max_length=200) diff --git a/core/views/scans.py b/core/views/scans.py index 7d933c7..fda3d6d 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -1,5 +1,6 @@ import os, stat import re +import datetime from pathlib import Path from urllib.parse import urljoin, unquote as urlunquote from urllib.request import urlopen @@ -8,7 +9,7 @@ from django.conf import settings from django.shortcuts import render from django.http import HttpResponse -from troggle.core.models.survex import Wallet, SingleScan +from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock from troggle.core.models.caves import GetCaveLookup from troggle.core.views.expo import getmimetype #import parsers.surveys @@ -21,9 +22,43 @@ need to check if inavlid query string is invalid, or produces multiple replies and render a user-friendly error page. ''' +def populatewallet(w): + '''Copy survex data here just for display, not permanently + ''' + # {% for personrole in wallet.survexblock.survexpersonrole_set.all %} + # {% if personrole.personexpedition %} + # {{personrole.personname}} + # {% else %} + # {{personrole.personname}} + # {% endif %} + # {% endfor %} + + survexpeople = [] + blocks = SurvexBlock.objects.filter(scanswallet = w) + for b in blocks: + for personrole in b.survexpersonrole_set.all(): + survexpeople.append(personrole.personname) + w.people = list(set(survexpeople)) # remove duplicates + +def datewallet(w, earliest): + blocks = SurvexBlock.objects.filter(scanswallet = w) + for b in blocks: + if b.date < earliest: + earliest = b.date + w.date = earliest + +def caveifywallet(w): + print('*') + blocks = SurvexBlock.objects.filter(scanswallet = w) + for b in blocks: + # 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 walletslistyear(request, year): - '''Page which displays a list of all the wallets in a specific year + '''Page which displays a list of all the wallets in a specific year - TO BE WRITTEN ''' if year < 1976 or year > 2050: return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'}) @@ -35,16 +70,38 @@ def walletslistyear(request, year): def cavewallets(request, caveid): '''Returns all the wallets for just one cave ''' + Gcavelookup = GetCaveLookup() if caveid in Gcavelookup: cave = Gcavelookup[caveid] else: return render(request,'errors/badslug.html', {'badslug': caveid}) + earliest = datetime.datetime.now().date() + # remove duplication. SOrting is done in the template wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) # NB a filtered set manywallets = list(wallets) - + + + for w in manywallets: + 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 not w.date(): + datewallet(w, earliest) + + c = w.cave() + + if not c: + caveifywallet(w) + return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave}) def oldwallet(request, path): diff --git a/templates/cavewallets.html b/templates/cavewallets.html index 49a36e3..51e5d76 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -12,7 +12,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c

This lists all the files in a wallet, some of which may not be for this specific cave.

Scans folderFilesSurvex blocksCave
WalletWallet DateWallet NameScansSurvex blocksSurvex datesDrawings using these scans
{{scanswallet.walletname}}{{scanswallet.singlescan_set.all|length}}{{wallet.walletname}}{{wallet.date}}{{wallet.name}}{{wallet.singlescan_set.all|length}} - {% for survexblock in scanswallet.survexblock_set.all %} + {% for survexblock in wallet.survexblock_set.all %} {{survexblock}} {% endfor %} - {% for survexblock in scanswallet.survexblock_set.all %} - {% ifchanged survexblock.survexfile.cave %} - /{{survexblock.survexfile.cave.slug}} - {% endifchanged %} - + {% for survexblock in wallet.survexblock_set.all %} + {{survexblock.date}}   + {% endfor %} + + {% for drawing in wallet.drawingfile_set.all %} + {{drawing.dwgpath}}
+ {% empty %} + (no Tunnel drawings found: but there might be Therion drawings) {% endfor %}
{{dwgfile.npaths}} - {% for scanswallet in dwgfile.manywallets.all %} + {% for scanswallet in dwgfile.dwgwallets.all %} {{scanswallet.walletname}} {% endfor %}
- + {% for wallet in manywallets|dictsort:"walletname" %} @@ -20,6 +20,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c + - +
WalletWallet DateWallet NamePeopleScansSurvex blocksSurvex datesDrawings using these scans
WalletWallet DateWallet NamePeopleCaveScansSurvex blocksDrawings using these scans
{{wallet.walletname}}{{wallet.date}} {{wallet.name}} {{wallet.people}}{{wallet.cave}} {{wallet.singlescan_set.all|length}} @@ -27,11 +28,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {{survexblock}} {% endfor %} - {% for survexblock in wallet.survexblock_set.all %} - {{survexblock.date}}   - {% endfor %} - {% for drawing in wallet.drawingfile_set.all %} {{drawing.dwgpath}}
-- cgit v1.2.3 From c1ba6a39a5f556d832da22e1f8e8ab33494f755b Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 31 Jul 2022 01:02:02 +0300 Subject: Wallets by year and by cave --- core/models/survex.py | 10 ++++++++++ core/views/scans.py | 45 ++++++++++++++++++++++++++++++++++++++------ templates/base.html | 8 ++++---- templates/cavewallets.html | 9 ++++++--- templates/manywallets.html | 5 +++++ templates/svxcavesingle.html | 1 + templates/yearwallets.html | 45 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 templates/yearwallets.html (limited to 'core/views/scans.py') diff --git a/core/models/survex.py b/core/models/survex.py index 79a645e..a84a37e 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -190,6 +190,16 @@ class Wallet(models.Model): raise return waldata + + def year(self): + if self.walletname[4] != "#": + return None + year = int(self.walletname[0:4]) + if year < 1976 or year > 2050: + return None + else: + return str(year) + # Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it def date(self): diff --git a/core/views/scans.py b/core/views/scans.py index fda3d6d..6ecae2b 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -20,6 +20,9 @@ by looking inside the file before being served. need to check if inavlid query string is invalid, or produces multiple replies and render a user-friendly error page. + +Note that datewallet(), caveifywallet() etc do NOT save the object to the db. They are ephemeral, just for the page rendering of the +manywallets dict. ''' def populatewallet(w): @@ -42,13 +45,13 @@ def populatewallet(w): def datewallet(w, earliest): blocks = SurvexBlock.objects.filter(scanswallet = w) - for b in blocks: - if b.date < earliest: - earliest = b.date + for b in blocks: + if b.date: + if b.date < earliest: + earliest = b.date w.date = earliest def caveifywallet(w): - print('*') blocks = SurvexBlock.objects.filter(scanswallet = w) for b in blocks: # NB b.cave is not populated by parser. Use b.survexfile.cave instead, or we could parse b.survexpath @@ -64,7 +67,38 @@ def walletslistyear(request, year): return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'}) else: year = str(year) - return render(request, 'errors/generic.html', {'message': 'This page logic not implemented yet'}) + #return render(request, 'errors/generic.html', {'message': 'This page logic not implemented yet'}) + earliest = datetime.datetime.now().date() + + manywallets = [] + wallets = Wallet.objects.all() + for w in wallets: + + if year == w.year(): + print(w.year(), w) + manywallets.append(w) + else: + print("NOT WANTED",year, w.year()) + continue + + 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 not w.date(): + datewallet(w, earliest) + + c = w.cave() + if not c: + caveifywallet(w) + + return render(request, 'yearwallets.html', { 'manywallets':manywallets, 'settings': settings, 'year': year}) + def cavewallets(request, caveid): @@ -98,7 +132,6 @@ def cavewallets(request, caveid): datewallet(w, earliest) c = w.cave() - if not c: caveifywallet(w) diff --git a/templates/base.html b/templates/base.html index 8f3f562..6d43e63 100644 --- a/templates/base.html +++ b/templates/base.html @@ -36,8 +36,8 @@ Drawings | Upload Drawings | Upload Photos | - 290 (FGH) | - 359 (Homecoming) | + 290 (FGH) | + 359 (Homecoming) |
Data Issues | @@ -48,8 +48,8 @@ expoers | survey lengths | statistics | - Expo2018 | - Expo2019 | + Wallets(2019) | + Expo(2019) | import/export | Django admin diff --git a/templates/cavewallets.html b/templates/cavewallets.html index 51e5d76..3208927 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -10,9 +10,13 @@ plans and elevations. It also contains scans of centre-line survex output on whi 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.

This lists all the files in a wallet, some of which may not be for this specific cave. +

See also wallets +

    +
  • per year, e.g. 2019 +
- + {% for wallet in manywallets|dictsort:"walletname" %} @@ -20,9 +24,8 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c - - +
WalletWallet DateWallet NamePeopleCaveScansSurvex blocksDrawings using these scans
WalletWallet DateWallet NamePeopleScansSurvex blocksDrawings using these scans
{{wallet.walletname}}{{wallet.date}} {{wallet.name}} {{wallet.people}}{{wallet.cave}}{{wallet.singlescan_set.all|length}}{{wallet.singlescan_set.all|length}} {% for survexblock in wallet.survexblock_set.all %} {{survexblock}} diff --git a/templates/manywallets.html b/templates/manywallets.html index 7fc04cb..44d097f 100644 --- a/templates/manywallets.html +++ b/templates/manywallets.html @@ -9,6 +9,11 @@ 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. +

See also wallets +

Cave description: {{cave.url}} +

Wallets: {{cave|safe}}

{% for survexdirectory in cave.survexdirectory_set.all %} diff --git a/templates/yearwallets.html b/templates/yearwallets.html new file mode 100644 index 0000000..87843d2 --- /dev/null +++ b/templates/yearwallets.html @@ -0,0 +1,45 @@ +{% extends "base.html" %} + +{% block title %}One Year Survey scans folders (wallets){% endblock %} + +{% block content %} +

Wallets for {{year}}

+

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. +

This lists all the files in a wallet, some of which may not be for this specific cave. +

See also wallets +

+ + +{% for wallet in manywallets|dictsort:"walletname" %} + + + + + + + + + + + + + +{% endfor %} +
WalletWallet DateWallet NamePeopleCaveScansSurvex blocksDrawings using these scans
{{wallet.walletname}}{{wallet.date}}{{wallet.name}}{{wallet.people}}{{wallet.cave}}{{wallet.singlescan_set.all|length}} + {% for survexblock in wallet.survexblock_set.all %} + {{survexblock}} + {% endfor %} + + {% for drawing in wallet.drawingfile_set.all %} + {{drawing.dwgpath}}
+ {% empty %} + (no Tunnel drawings found: but there might be Therion drawings) + {% endfor %} +
+ +{% endblock %} \ No newline at end of file -- cgit v1.2.3 From a2a5e9200ec5a588729a19684bba9c045dad8ef6 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 31 Jul 2022 18:58:46 +0300 Subject: 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 (limited to 'core/views/scans.py') 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" %} - + + + + + + + + + + + + + + +{% for wallet in manywallets|dictsort:"walletname" %} + + + + + + + + + + + + + + + + + + +{% endfor %} +
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

+
SCQNPETW
{{wallet.walletname}}{{wallet.date}}{{wallet.cave}}{{wallet.name}}        
+
{% for wallet in manywallets|dictsort:"walletname" %} @@ -43,4 +85,5 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {% endfor %}
WalletWallet DateWallet NameOther PeopleCaveScansSurvex blocksDrawings using these scans
+ {% endblock %} \ No newline at end of file diff --git a/templates/walletform.html b/templates/walletform.html index 0bde7be..37b1c11 100644 --- a/templates/walletform.html +++ b/templates/walletform.html @@ -156,10 +156,10 @@
- +
- +
-- cgit v1.2.3 From eed35d01a86a365d464a6b1584d12b9cb40652f6 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 1 Aug 2022 15:55:20 +0300 Subject: tick lists now on 3 wallets reports --- core/views/scans.py | 147 +++++++++++++++++-------------------------- templates/base.html | 17 +++-- templates/cavewallets.html | 5 +- templates/personwallets.html | 43 +------------ templates/wallet_table.html | 40 ++++++++++++ templates/yearwallets.html | 5 +- 6 files changed, 115 insertions(+), 142 deletions(-) create mode 100644 templates/wallet_table.html (limited to 'core/views/scans.py') diff --git a/core/views/scans.py b/core/views/scans.py index 94fb560..0ffdb22 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -31,14 +31,6 @@ manywallets dict. def populatewallet(w): '''Copy survex data here just for display, not permanently ''' - # {% for personrole in wallet.survexblock.survexpersonrole_set.all %} - # {% if personrole.personexpedition %} - # {{personrole.personname}} - # {% else %} - # {{personrole.personname}} - # {% endif %} - # {% endfor %} - survexpeople = [] blocks = SurvexBlock.objects.filter(scanswallet = w) for b in blocks: @@ -60,11 +52,34 @@ def datewallet(w, earliest): w.date = first def caveifywallet(w): + '''Gets the cave from the list of survex files, + only selects one of them though. Only used for display. + ''' blocks = SurvexBlock.objects.filter(scanswallet = w) for b in blocks: # 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 + w.cave = b.survexfile.cave # just gets the last one, randomly. SHould make this a list or many:many ideally + +def fillblankpeople(w): + 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) + +def fillblankothers(w): + earliest = datetime.datetime.now().date() + if not w.date(): + datewallet(w, earliest) + + c = w.cave() + if not c: + caveifywallet(w) + def walletslistperson(request, first_name, last_name): '''Page which displays a list of all the wallets for a specific person @@ -72,6 +87,18 @@ def walletslistperson(request, first_name, last_name): ''' # 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 + def tickspersonwallet(p): + manywallets = [] + wallets = Wallet.objects.all() + for w in wallets: + w.persons = w.people() # ephemeral attribute for web page + fillblankpeople(w) + if w.persons: + if p.fullname in w.persons: + manywallets.append(w) + fillblankothers(w) + w.ticks = w.get_ticks() # the complaints in colour form + return manywallets try: if last_name: @@ -82,79 +109,37 @@ def walletslistperson(request, first_name, last_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 - w.ticks = {} # ephemeral tick boxes display - # 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 w.persons: - 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) - - w.ticks = w.get_ticks() # the complaints in colour form + manywallets = tickspersonwallet(p) 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 ''' + def ticksyearwallet(year): + manywallets = [] + wallets = Wallet.objects.all() + for w in wallets: + + if year == w.year(): + manywallets.append(w) + fillblankpeople(w) + fillblankothers(w) + w.ticks = w.get_ticks() # the complaints in colour form + else: + continue + + return manywallets + if year < 1976 or year > 2050: return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'}) else: year = str(year) #return render(request, 'errors/generic.html', {'message': 'This page logic not implemented yet'}) - earliest = datetime.datetime.now().date() - - manywallets = [] - wallets = Wallet.objects.all() - for w in wallets: - - if year == w.year(): - print(w.year(), w) - manywallets.append(w) - else: - continue - 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 not w.date(): - datewallet(w, earliest) - - c = w.cave() - if not c: - caveifywallet(w) + manywallets = ticksyearwallet(year) return render(request, 'yearwallets.html', { 'manywallets':manywallets, 'settings': settings, 'year': year}) @@ -163,39 +148,23 @@ def walletslistyear(request, year): def cavewallets(request, caveid): '''Returns all the wallets for just one cave ''' - Gcavelookup = GetCaveLookup() if caveid in Gcavelookup: cave = Gcavelookup[caveid] else: return render(request,'errors/badslug.html', {'badslug': caveid}) - earliest = datetime.datetime.now().date() - # remove duplication. SOrting is done in the template wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) # NB a filtered set manywallets = list(wallets) - for w in manywallets: - 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 not w.date(): - datewallet(w, earliest) - - c = w.cave() - if not c: - caveifywallet(w) - + fillblankpeople(w) + fillblankothers(w) + w.ticks = w.get_ticks() # the complaints in colour form return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave}) + def oldwallet(request, path): '''Now called only for non-standard wallet structures for pre-2000 wallets ''' diff --git a/templates/base.html b/templates/base.html index 6d43e63..a25e13c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -56,7 +56,7 @@ @@ -65,16 +65,15 @@ {% block contentheader %} {% endblock %} - + {% block content %} REPLACE : The content {% endblock %} - - + + diff --git a/templates/cavewallets.html b/templates/cavewallets.html index 8fd5d83..8ce1da1 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -14,8 +14,9 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c +{% include 'wallet_table.html' %} +
{% for wallet in manywallets|dictsort:"walletname" %} @@ -33,7 +34,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {% endfor %} -
WalletWallet DateWallet NamePeopleScansSurvex blocksDrawings using these scans
+ {% for drawing in wallet.drawingfile_set.all %} {{drawing.dwgpath}}
{% empty %} diff --git a/templates/personwallets.html b/templates/personwallets.html index 5586485..f513e20 100644 --- a/templates/personwallets.html +++ b/templates/personwallets.html @@ -15,46 +15,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
  • per cave, e.g. 1623/161 - - - - - - - - - - - - - - - - - - - -{% for wallet in manywallets|dictsort:"walletname" %} - - - - - - - - - - - - - - - - - - -{% endfor %} -
    WalletWallet DateCaveWallet NameSCQNPETW
    {{wallet.walletname}}{{wallet.date}}{{wallet.cave}}{{wallet.name}}        
    +{% include 'wallet_table.html' %}
    @@ -74,7 +35,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {% endfor %} -
    WalletWallet DateWallet NameOther PeopleCaveScansSurvex blocksDrawings using these scans
    + {% for drawing in wallet.drawingfile_set.all %} {{drawing.dwgpath}}
    {% empty %} diff --git a/templates/wallet_table.html b/templates/wallet_table.html new file mode 100644 index 0000000..b239e91 --- /dev/null +++ b/templates/wallet_table.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + +{% for wallet in manywallets|dictsort:"walletname" %} + + + + + + + + + + + + + + + + + + +{% endfor %} +
    WalletWallet DateCaveWallet NameSCQNPETW
    {{wallet.walletname}}{{wallet.date}}{{wallet.cave}}{{wallet.name}}        
    diff --git a/templates/yearwallets.html b/templates/yearwallets.html index ce061c0..33b86ef 100644 --- a/templates/yearwallets.html +++ b/templates/yearwallets.html @@ -14,6 +14,9 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
  • per cave, e.g. 1623/161
  • per person, e.g. Michael Sargent + +{% include 'wallet_table.html' %} +
    {% for wallet in manywallets|dictsort:"walletname" %} @@ -32,7 +35,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {% endfor %} -
    WalletWallet DateWallet NamePeopleCaveScansSurvex blocksDrawings using these scans
    + {% for drawing in wallet.drawingfile_set.all %} {{drawing.dwgpath}}
    {% empty %} -- cgit v1.2.3