summaryrefslogtreecommitdiffstats
path: root/core/views/scans.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/views/scans.py')
-rw-r--r--core/views/scans.py59
1 files changed, 39 insertions, 20 deletions
diff --git a/core/views/scans.py b/core/views/scans.py
index 9fd58d6..a7ce27a 100644
--- a/core/views/scans.py
+++ b/core/views/scans.py
@@ -8,6 +8,7 @@ from urllib.request import urlopen
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse
+from django.db import transaction
from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock
from troggle.core.models.troggle import Person, Expedition
@@ -48,6 +49,9 @@ def populatewallet(w):
w.persons = list(set(survexpeople))
def datewallet(w, earliest):
+ '''Gets the date of the youngest survexblock associated with the wallet
+ REFACTOR this to do the whole date-getting task
+ '''
first = earliest
blocks = SurvexBlock.objects.filter(scanswallet = w)
for b in blocks:
@@ -59,6 +63,7 @@ def datewallet(w, earliest):
w.date = None
else:
w.date = first.isoformat()
+ return w.date
def caveifywallet(w):
'''Gets the cave from the list of survex files,
@@ -94,10 +99,13 @@ def fillblankpeople(w):
# print(f' - {wp=} {nobody=}')
populatewallet(w)
-def fillblankothers(w):
- earliest = datetime.datetime.now().date()
- if not w.date():
- datewallet(w, earliest)
+def fillblankothers(w):
+ if not w.walletdate:
+ earliest = datetime.datetime.now().date()
+ if not w.date(): # sets .walletdate as a side-effect, gets it from JSON
+ d =datewallet(w, earliest) # if nothing in JASON, it looks at the survex blocks
+ w.walletdate = d
+ w.save()
Gcavelookup = GetCaveLookup()
@@ -140,6 +148,8 @@ def walletslistperson(request, first_name, last_name):
w.ticks = w.get_ticks() # the complaints in colour form
fixsurvextick(w, w.ticks)
return manywallets
+
+ print(f"-walletslistperson")
try:
if last_name:
@@ -153,37 +163,43 @@ def walletslistperson(request, first_name, last_name):
manywallets = tickspersonwallet(p)
expeditions = Expedition.objects.all()
+ print(f"--")
return render(request, 'personwallets.html', { 'manywallets':manywallets, 'settings': settings, 'person': p, 'expeditions': expeditions})
+def setwalletsdates():
+ wallets = Wallet.objects.filter(walletdate=None)
+ print(f"undated wallets: {len(wallets)}")
+ for w in wallets:
+ w.walletdate = w.date()
+ w.save()
+
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.
+ We have a field .walletyear, which we set on import.
'''
def ticksyearwallet(year):
manywallets = []
- wallets = Wallet.objects.all()
+ wallets = Wallet.objects.filter(walletyear__year=year)
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, from the json file on disc
- fixsurvextick(w, w.ticks)
- else:
- continue
+ manywallets.append(w)
+ fillblankpeople(w)
+ fillblankothers(w)
+ w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc
+ fixsurvextick(w, w.ticks)
return manywallets
-
+ print(f"-walletslistyear")
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'})
-
+
+ year = str(year)
manywallets = ticksyearwallet(year)
expeditions = Expedition.objects.all()
- expedition = Expedition.objects.filter(year=year)
+ expedition = expeditions.filter(year=year)
+ print(f"--")
return render(request, 'yearwallets.html', { 'manywallets':manywallets, 'settings': settings, 'year': year, 'expeditions': expeditions, 'expedition': expedition})
@@ -191,6 +207,8 @@ def walletslistyear(request, year):
def cavewallets(request, caveid):
'''Returns all the wallets for just one cave
'''
+ print(f"-cavewalletsl")
+
Gcavelookup = GetCaveLookup()
if caveid in Gcavelookup:
cave = Gcavelookup[caveid]
@@ -224,6 +242,7 @@ def cavewallets(request, caveid):
w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc
fixsurvextick(w, w.ticks)
expeditions = Expedition.objects.all()
+ print(f"--")
return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave, 'expeditions': expeditions})