2022-07-29 18:55:19 +01:00
|
|
|
import datetime
|
2021-05-03 20:36:29 +01:00
|
|
|
from pathlib import Path
|
2023-01-19 18:35:56 +00:00
|
|
|
from urllib.parse import unquote as urlunquote
|
2021-05-03 20:36:29 +01:00
|
|
|
|
|
|
|
from django.conf import settings
|
2023-01-19 18:35:56 +00:00
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.shortcuts import render
|
2021-05-03 20:36:29 +01:00
|
|
|
|
2022-07-21 08:32:11 +01:00
|
|
|
from troggle.core.models.caves import GetCaveLookup
|
2023-10-04 16:22:54 +01:00
|
|
|
from troggle.core.models.survex import SingleScan, SurvexBlock, SurvexPersonRole
|
|
|
|
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
|
2024-12-15 18:54:47 +00:00
|
|
|
from troggle.core.models.wallets import Wallet
|
|
|
|
from troggle.core.utils import DatabaseResetOngoing, current_expo
|
2021-05-03 20:36:29 +01:00
|
|
|
from troggle.core.views.expo import getmimetype
|
2023-08-02 16:23:04 +01:00
|
|
|
from troggle.parsers.caves import add_cave_to_pending_list
|
2023-10-04 16:22:54 +01:00
|
|
|
from troggle.parsers.people import GetPersonExpeditionNameLookup
|
|
|
|
from troggle.parsers.survex import set_walletdate
|
2021-05-03 20:36:29 +01:00
|
|
|
|
2023-11-04 16:28:14 +00:00
|
|
|
"""
|
2023-02-01 23:43:05 +00:00
|
|
|
Note that caveifywallet() etc do NOT save the object to the db. They are ephemeral, just for the page rendering of the
|
2022-07-30 23:02:02 +01:00
|
|
|
manywallets dict.
|
2023-11-04 16:28:14 +00:00
|
|
|
"""
|
2022-08-24 17:08:08 +01:00
|
|
|
|
2023-11-04 16:28:14 +00:00
|
|
|
todo="""
|
|
|
|
- one of these views serves files as binary blobs, and simply set the mime type based on the file extension,
|
|
|
|
as does the urls.py dispatcher which sends them here. Here they should actually have the filetype checked
|
|
|
|
by looking inside the file before being served.
|
2023-10-04 20:23:26 +01:00
|
|
|
|
2023-11-04 16:28:14 +00:00
|
|
|
- need to check if inavlid query string is invalid, or produces multiple replies
|
|
|
|
and render a user-friendly error page.
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
2023-10-24 23:56:30 +01:00
|
|
|
|
|
|
|
def fix_manywallets(many):
|
|
|
|
for w in many:
|
|
|
|
fillblankpeople(w)
|
|
|
|
fillblankothers(w)
|
|
|
|
w.ticks = w.get_ticks() # the complaints in colour form
|
|
|
|
fixsurvextick(w, w.ticks)
|
|
|
|
|
2022-07-29 18:55:19 +01:00
|
|
|
def populatewallet(w):
|
2023-10-24 23:56:30 +01:00
|
|
|
"""Need to tidy this up, now all the work is done at parse time not here
|
2023-10-04 16:22:54 +01:00
|
|
|
Only gets data from the survex file when it was parsed on import, or edited (& thus parsed) online,
|
|
|
|
so doesn't work if there was no *ref value
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
2023-10-24 23:56:30 +01:00
|
|
|
w.slugpeople = w.persons.all()
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-07-29 18:55:19 +01:00
|
|
|
|
|
|
|
def caveifywallet(w):
|
2023-10-23 18:24:05 +01:00
|
|
|
"""Gets the block names from the list of blocks, set by the survex parser
|
2023-10-21 14:22:20 +01:00
|
|
|
"""
|
2023-01-30 19:04:36 +00:00
|
|
|
# print(f' - Caveify {w=}')
|
2022-08-24 16:28:15 +01:00
|
|
|
blocknames = []
|
2023-01-30 19:04:36 +00:00
|
|
|
blocks = SurvexBlock.objects.filter(scanswallet=w)
|
|
|
|
for b in blocks:
|
2022-07-29 18:55:19 +01:00
|
|
|
# NB b.cave is not populated by parser. Use b.survexfile.cave instead, or we could parse b.survexpath
|
2023-10-23 01:24:34 +01:00
|
|
|
#if b.survexfile.cave:
|
|
|
|
#w.caves.add(b.survexfile.cave)
|
2022-08-24 16:28:15 +01:00
|
|
|
if b.name:
|
|
|
|
blocknames.append(b.name)
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-08-24 16:28:15 +01:00
|
|
|
if w.name():
|
|
|
|
w.displaynames = [w.name()]
|
|
|
|
else:
|
|
|
|
w.displaynames = blocknames
|
2023-01-30 19:04:36 +00:00
|
|
|
|
|
|
|
|
2022-08-01 13:55:20 +01:00
|
|
|
def fillblankpeople(w):
|
2023-10-04 16:22:54 +01:00
|
|
|
"""Find people attached to a wallet via the survex files
|
|
|
|
if no one explicitly attached.
|
|
|
|
the JSON string which may OR MAY NOT be formatted as a list.
|
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
w.slugpeople is from the survexfiles
|
|
|
|
w.persons is from the explicit list of peoples' names in the wallet
|
|
|
|
The template choses how to display them.
|
2023-10-04 16:22:54 +01:00
|
|
|
"""
|
|
|
|
def nobody(wplist):
|
|
|
|
if len(wplist) > 1:
|
|
|
|
return False
|
|
|
|
|
|
|
|
nobod = wp[0].lower()
|
|
|
|
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
wp = w.people() # just a list of names as strings, direct from JSON.
|
2023-10-04 16:22:54 +01:00
|
|
|
if not isinstance(wp, list): # might be None
|
|
|
|
print(f"{w} NOT A LIST {type(wp)}: {wp}")
|
2023-01-30 19:04:36 +00:00
|
|
|
populatewallet(w)
|
2023-10-04 16:22:54 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
if not wp: # e.g. empty list
|
|
|
|
# print(f"{w} {wp=}")
|
|
|
|
populatewallet(w) # sets w.slugpeople
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if nobody(wp):
|
|
|
|
populatewallet(w) # sets w.slugpeople
|
2023-01-30 19:04:36 +00:00
|
|
|
else:
|
2023-10-24 23:56:30 +01:00
|
|
|
w.peeps = parse_name_list(w)
|
2023-10-05 12:11:05 +01:00
|
|
|
populatewallet(w) # sets w.slugpeople
|
|
|
|
if hasattr(w, "slugpeople"):
|
2023-10-24 23:56:30 +01:00
|
|
|
w.peeps = w.peeps.difference(w.slugpeople)
|
2023-10-04 16:22:54 +01:00
|
|
|
return
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
|
2023-09-16 11:53:05 +01:00
|
|
|
def is_cave(wallet, id):
|
|
|
|
if not id:
|
|
|
|
return False
|
2023-08-02 16:23:04 +01:00
|
|
|
Gcavelookup = GetCaveLookup()
|
|
|
|
if id in Gcavelookup:
|
|
|
|
return True
|
|
|
|
else:
|
2023-10-21 14:22:20 +01:00
|
|
|
# Historic wallets were all 1623 area. So, just for wallets,
|
2023-09-16 11:53:05 +01:00
|
|
|
# assume it is 1623-xxx
|
|
|
|
if f"1623-{id}" in Gcavelookup:
|
2023-09-26 17:44:06 +01:00
|
|
|
print(f" - Should modify wallet {wallet} to use 1623- prefix for cave <{id}>")
|
|
|
|
Gcavelookup[id] = Gcavelookup[f"1623-{id}"] # restoring an ambiguous alias, BAD idea.
|
2023-09-16 11:53:05 +01:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
print(f" - Wallet {wallet} Failed to find cave object from id <{id}>")
|
|
|
|
if id.lower() != "unknown" and id != "":
|
2023-09-26 17:44:06 +01:00
|
|
|
print(f" - adding <{id}> to pendingcaves DataIssues")
|
2023-10-21 20:31:33 +01:00
|
|
|
add_cave_to_pending_list(id, wallet, f"Wallet {wallet} - Could not find cave id <{id}>")
|
2023-09-16 11:53:05 +01:00
|
|
|
return False
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-12-20 00:07:55 +00:00
|
|
|
def fillblankothers(w):
|
2023-10-23 18:24:05 +01:00
|
|
|
# has this already been done? Do we need to do it on every refresh ?
|
2022-12-20 00:07:55 +00:00
|
|
|
if not w.walletdate:
|
2023-02-01 23:43:05 +00:00
|
|
|
set_walletdate(w)
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-09-21 23:37:25 +01:00
|
|
|
Gcavelookup = GetCaveLookup()
|
|
|
|
|
2023-10-21 14:22:20 +01:00
|
|
|
caveifywallet(w)
|
2023-10-23 18:24:05 +01:00
|
|
|
|
|
|
|
# Is this not done when we scan for wallets when we create them in the first place ?
|
|
|
|
# needs to be refactored into models/wallets.py anyway
|
2022-09-21 23:37:25 +01:00
|
|
|
wcaveid = w.cave()
|
2024-03-14 23:59:39 +00:00
|
|
|
if wcaveid:
|
|
|
|
if wcaveid == "":
|
|
|
|
if type(wcaveid) == list:
|
|
|
|
for i in wcaveid:
|
|
|
|
i = i.strip("' []\"")
|
|
|
|
if is_cave(w,i):
|
|
|
|
w.caves.add(Gcavelookup[i])
|
|
|
|
elif wcaveid.find(',') != -1:
|
|
|
|
# it's a list of cave ids as a string
|
|
|
|
ids = wcaveid.split(',')
|
|
|
|
for i in ids:
|
|
|
|
i = i.strip("' []\"")
|
|
|
|
if is_cave(w,i):
|
|
|
|
w.caves.add(Gcavelookup[i])
|
|
|
|
else:
|
|
|
|
if is_cave(w,wcaveid):
|
2023-10-21 14:22:20 +01:00
|
|
|
w.caves.add(Gcavelookup[i])
|
|
|
|
|
2023-08-02 16:23:04 +01:00
|
|
|
|
2023-01-30 19:04:36 +00:00
|
|
|
def fixsurvextick(w, ticks):
|
|
|
|
ticks["S"] = w.fixsurvextick(ticks["S"])
|
2022-09-21 23:37:25 +01:00
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
def parse_name_list(w):
|
|
|
|
"""Given a list of strings, which are names, and the year of an expo,
|
|
|
|
return a set of Persons
|
|
|
|
"""
|
|
|
|
namelist = w.people()
|
|
|
|
peeps = set()
|
|
|
|
expo = Expedition.objects.get(year=w.year())
|
|
|
|
crew = GetPersonExpeditionNameLookup(expo)
|
|
|
|
|
|
|
|
for n in namelist:
|
|
|
|
if n.lower() in crew:
|
|
|
|
peeps.add(crew[n.lower()].person)
|
|
|
|
else:
|
2023-10-23 20:54:46 +01:00
|
|
|
if check := n.startswith("*"): #ignore people flagged as guests or not-expo anyway, such as ARGE
|
2023-10-05 12:45:46 +01:00
|
|
|
continue
|
2023-10-05 12:11:05 +01:00
|
|
|
nobod = n.lower()
|
|
|
|
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
|
2023-10-05 12:45:46 +01:00
|
|
|
continue
|
2023-10-05 12:11:05 +01:00
|
|
|
else:
|
|
|
|
wurl = f"/walletedit/{w.walletname.replace('#',':')}"
|
2023-10-23 20:54:46 +01:00
|
|
|
message = f"{w} name '{n.lower()}' NOT found in GetPersonExpeditionNameLookup({w.year()}) n.startswith* = {check} ?!"
|
2023-10-05 12:11:05 +01:00
|
|
|
print(message)
|
|
|
|
DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl)
|
|
|
|
return peeps
|
|
|
|
|
2023-10-01 13:55:28 +01:00
|
|
|
def walletslistperson(request, slug):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Page which displays a list of all the wallets for a specific person
|
|
|
|
"""
|
2023-10-04 16:22:54 +01:00
|
|
|
|
|
|
|
# Remember that 'personexpedition__expedition' is interpreted by Django to mean the
|
|
|
|
# 'expedition' object which is connected by a foreign key to the 'personexpedition'
|
|
|
|
# object, which is a field of the PersonLogEntry object:
|
|
|
|
# PersonLogEntry.objects.filter(personexpedition__expedition=expo)
|
|
|
|
|
|
|
|
def personwallet(p):
|
|
|
|
manywallets = set()
|
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
# Get the persons from the survexblocks on the survexfiles attached to the wallet directly
|
2023-10-04 16:22:54 +01:00
|
|
|
sps = SurvexPersonRole.objects.filter(person=p)
|
|
|
|
for sp in sps:
|
|
|
|
w = sp.survexblock.scanswallet
|
|
|
|
if w:
|
|
|
|
manywallets.add(w)
|
2023-10-05 12:11:05 +01:00
|
|
|
|
|
|
|
# Now read the text strings in the list of wallet people and identify the person
|
2023-10-04 16:22:54 +01:00
|
|
|
pes = PersonExpedition.objects.filter(person=p)
|
|
|
|
for person_expo in pes:
|
|
|
|
expo = person_expo.expedition
|
|
|
|
year = expo.year
|
|
|
|
|
2023-10-05 12:11:05 +01:00
|
|
|
crew = GetPersonExpeditionNameLookup(expo)
|
2023-10-04 16:22:54 +01:00
|
|
|
wallets = Wallet.objects.filter(walletyear__year=year)
|
|
|
|
for w in wallets:
|
2023-10-05 12:11:05 +01:00
|
|
|
if w in manywallets:
|
|
|
|
# we already know this is a wallet we need to report on
|
2023-10-04 16:22:54 +01:00
|
|
|
continue
|
2023-10-05 12:11:05 +01:00
|
|
|
for n in w.people():
|
|
|
|
# if n.lower().startswith("lydia"):
|
|
|
|
# print(f"{w} {n=} ")
|
|
|
|
# for x in crew:
|
|
|
|
# if x.lower()==n.lower():
|
|
|
|
# print(f"{w} {n=} {x=}")
|
|
|
|
|
2023-10-04 16:22:54 +01:00
|
|
|
if n.lower() in crew:
|
|
|
|
if crew[n.lower()] == person_expo:
|
|
|
|
manywallets.add(w)
|
|
|
|
# print(f"{w} Found a non-survex wallet for {person_expo}")
|
|
|
|
else:
|
2023-10-05 12:11:05 +01:00
|
|
|
if n.startswith("*"): #ignore people flagged as guests or not-expo anyway, such as ARGE
|
|
|
|
pass
|
2023-10-04 16:22:54 +01:00
|
|
|
nobod = n.lower()
|
|
|
|
if nobod == "unknown" or nobod == "nobody" or nobod == " " or nobod == "":
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
wurl = f"/walletedit/{w.walletname.replace('#',':')}"
|
2023-10-04 21:34:36 +01:00
|
|
|
message = f"{w} name '{n.lower()}' NOT found in GetPersonExpeditionNameLookup({year}) ?!"
|
2023-10-04 16:22:54 +01:00
|
|
|
print(message)
|
2023-10-04 21:34:36 +01:00
|
|
|
DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl)
|
2023-10-04 16:22:54 +01:00
|
|
|
|
2023-10-24 23:56:30 +01:00
|
|
|
fix_manywallets(manywallets)
|
2022-08-01 13:55:20 +01:00
|
|
|
return manywallets
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2023-02-03 22:19:51 +00:00
|
|
|
# print("-walletslistperson")
|
2023-10-01 13:55:28 +01:00
|
|
|
p = Person.objects.get(slug=slug)
|
2023-10-04 16:22:54 +01:00
|
|
|
|
|
|
|
manywallets = personwallet(p)
|
2022-10-15 19:28:56 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2023-10-21 20:31:33 +01:00
|
|
|
length_ug = 0.0
|
|
|
|
for w in manywallets:
|
2023-10-24 23:56:30 +01:00
|
|
|
print(w.persons)
|
2023-10-21 20:31:33 +01:00
|
|
|
for sb in w.survexblock_set.all():
|
|
|
|
length_ug += sb.legslength
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"personwallets.html",
|
2023-10-21 20:31:33 +01:00
|
|
|
{"manywallets": manywallets, "settings": settings, "person": p, "expeditions": expeditions,
|
2024-03-15 01:50:34 +00:00
|
|
|
"length_ug": length_ug, "year": current_expo()}
|
2023-01-30 19:04:36 +00:00
|
|
|
)
|
|
|
|
|
2022-07-27 21:22:46 +01:00
|
|
|
|
2022-12-20 00:07:55 +00:00
|
|
|
def setwalletsdates():
|
2023-02-01 23:43:05 +00:00
|
|
|
"""This sets all the undated wallets, but they should already all be dated on
|
|
|
|
import or on edit"""
|
2023-01-30 19:04:36 +00:00
|
|
|
wallets = Wallet.objects.filter(walletdate=None)
|
2022-12-20 00:07:55 +00:00
|
|
|
print(f"undated wallets: {len(wallets)}")
|
|
|
|
for w in wallets:
|
|
|
|
w.walletdate = w.date()
|
|
|
|
w.save()
|
|
|
|
|
2022-08-01 13:55:20 +01:00
|
|
|
|
2022-07-27 21:22:46 +01:00
|
|
|
def walletslistyear(request, year):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Page which displays a list of all the wallets in a specific year.
|
2022-12-20 00:07:55 +00:00
|
|
|
We have a field .walletyear, which we set on import.
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
|
|
|
|
2022-08-01 13:55:20 +01:00
|
|
|
def ticksyearwallet(year):
|
|
|
|
manywallets = []
|
2024-08-11 13:43:41 +01:00
|
|
|
try:
|
|
|
|
manywallets = Wallet.objects.filter(walletyear__year=year)
|
|
|
|
except OperationalError:
|
|
|
|
# Reset is ongoing on server
|
|
|
|
raise DatabaseResetOngoing(
|
|
|
|
f"Expo Database re-import ongoing on server.\nPlease wait 6 minutes.\n If still not working, contact a nerd."
|
|
|
|
)
|
2022-08-01 13:55:20 +01:00
|
|
|
|
2023-10-24 23:56:30 +01:00
|
|
|
fix_manywallets(manywallets)
|
2022-08-01 13:55:20 +01:00
|
|
|
return manywallets
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2023-02-03 22:19:51 +00:00
|
|
|
# print("-walletslistyear")
|
2022-07-27 21:22:46 +01:00
|
|
|
if year < 1976 or year > 2050:
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(request, "errors/generic.html", {"message": "Year out of range. Must be between 1976 and 2050"})
|
|
|
|
|
2022-12-20 00:07:55 +00:00
|
|
|
year = str(year)
|
2022-08-01 13:55:20 +01:00
|
|
|
manywallets = ticksyearwallet(year)
|
2023-10-24 23:56:30 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2022-12-20 00:07:55 +00:00
|
|
|
expedition = expeditions.filter(year=year)
|
2023-03-12 01:09:17 +00:00
|
|
|
length_ug = 0.0
|
|
|
|
for w in manywallets:
|
|
|
|
for sb in w.survexblock_set.all():
|
|
|
|
length_ug += sb.legslength
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"yearwallets.html",
|
|
|
|
{
|
|
|
|
"manywallets": manywallets,
|
|
|
|
"settings": settings,
|
|
|
|
"year": year,
|
|
|
|
"expeditions": expeditions,
|
|
|
|
"expedition": expedition,
|
2023-03-12 01:09:17 +00:00
|
|
|
"length_ug": length_ug,
|
2023-01-30 19:04:36 +00:00
|
|
|
},
|
|
|
|
)
|
2022-07-27 21:22:46 +01:00
|
|
|
|
2022-07-27 23:48:22 +01:00
|
|
|
|
|
|
|
def cavewallets(request, caveid):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Returns all the wallets for just one cave"""
|
2023-08-02 16:23:04 +01:00
|
|
|
print("-cavewallets")
|
2022-12-20 00:07:55 +00:00
|
|
|
|
2022-07-27 23:48:22 +01:00
|
|
|
Gcavelookup = GetCaveLookup()
|
|
|
|
if caveid in Gcavelookup:
|
|
|
|
cave = Gcavelookup[caveid]
|
|
|
|
else:
|
2023-02-02 11:19:46 +00:00
|
|
|
return render(request, "errors/badslug.html", {"badslug": f"{caveid} - from cavewallets()"})
|
2022-07-27 23:48:22 +01:00
|
|
|
|
2023-10-21 20:31:33 +01:00
|
|
|
wallets = cave.wallets.all()
|
2022-09-21 22:23:22 +01:00
|
|
|
manywallets = list(set(wallets))
|
2023-10-24 23:56:30 +01:00
|
|
|
fix_manywallets(manywallets)
|
|
|
|
|
2022-10-15 19:28:56 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2023-10-21 20:31:33 +01:00
|
|
|
length_ug = 0.0
|
|
|
|
for w in manywallets:
|
|
|
|
for sb in w.survexblock_set.all():
|
|
|
|
length_ug += sb.legslength
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"cavewallets.html",
|
2023-10-21 20:31:33 +01:00
|
|
|
{"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions,
|
2024-03-15 01:50:34 +00:00
|
|
|
"length_ug": length_ug, "year": current_expo()}
|
2023-01-30 19:04:36 +00:00
|
|
|
)
|
2022-07-27 21:22:46 +01:00
|
|
|
|
2022-08-01 13:55:20 +01:00
|
|
|
|
2022-03-18 11:28:35 +00:00
|
|
|
def oldwallet(request, path):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Now called only for non-standard wallet structures for pre-2000 wallets"""
|
2022-03-18 11:28:35 +00:00
|
|
|
# print([ s.walletname for s in Wallet.objects.all() ])
|
2023-01-30 19:04:36 +00:00
|
|
|
print(f"! - oldwallet path:{path}")
|
2021-05-03 20:36:29 +01:00
|
|
|
try:
|
2023-01-30 19:04:36 +00:00
|
|
|
wallet = Wallet.objects.get(walletname=urlunquote(path))
|
2024-03-15 01:50:34 +00:00
|
|
|
return render(request, "wallet_old.html", {"wallet": wallet, "settings": settings, "year": current_expo()})
|
2022-03-18 12:26:32 +00:00
|
|
|
except:
|
2023-01-30 19:04:36 +00:00
|
|
|
message = f"Scan folder error or not found '{path}' ."
|
2024-03-15 01:50:34 +00:00
|
|
|
return render(request, "errors/generic.html", {"message": message,"year": current_expo()})
|
2022-03-18 12:26:32 +00:00
|
|
|
|
2021-05-03 20:36:29 +01:00
|
|
|
|
|
|
|
def scansingle(request, path, file):
|
2023-08-02 16:23:04 +01:00
|
|
|
"""sends a single binary file to the user for display - browser decides how using mimetype
|
|
|
|
This is very unsafe"""
|
2021-05-03 20:36:29 +01:00
|
|
|
try:
|
2022-10-15 16:37:46 +01:00
|
|
|
wallet = Wallet.objects.get(walletname=urlunquote(path))
|
2021-05-03 20:36:29 +01:00
|
|
|
singlescan = SingleScan.objects.get(wallet=wallet, name=file)
|
2022-10-15 16:37:46 +01:00
|
|
|
imagefile = Path(singlescan.ffile, file)
|
|
|
|
if imagefile.is_file():
|
|
|
|
message = f" - scansingle {imagefile} {path}:{file}:{getmimetype(file)}:"
|
|
|
|
print(message)
|
2023-01-30 19:04:36 +00:00
|
|
|
return HttpResponse(content=open(imagefile, "rb"), content_type=getmimetype(file)) # any type of image
|
2022-10-15 16:37:46 +01:00
|
|
|
else:
|
2023-01-30 19:04:36 +00:00
|
|
|
message = f"Scan folder file '{imagefile}' not found. {path=} {file=}"
|
2022-10-15 16:37:46 +01:00
|
|
|
print(message)
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(request, "errors/generic.html", {"message": message})
|
2022-10-15 16:37:46 +01:00
|
|
|
|
2021-05-03 20:36:29 +01:00
|
|
|
except:
|
2023-01-30 19:04:36 +00:00
|
|
|
message = f"Scan folder or scan item access error '{path}' and '{file}'."
|
|
|
|
return render(request, "errors/generic.html", {"message": message})
|
2021-05-03 20:36:29 +01:00
|
|
|
|
|
|
|
|
2022-07-27 21:22:46 +01:00
|
|
|
def allscans(request):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Returns all the wallets in the system, we would like to use
|
2023-02-10 00:05:04 +00:00
|
|
|
the Django queryset SQL optimisation https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related
|
2022-07-05 12:14:03 +01:00
|
|
|
to get the related singlescan and survexblock objects but that requires rewriting this to do the query on those, not on
|
|
|
|
the wallets
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
|
|
|
manywallets = Wallet.objects.all() # NB all of them
|
2022-07-05 12:14:03 +01:00
|
|
|
# manywallets = Wallet.objects.all().prefetch_related('singlescan') fails as the link is defined on 'singlescan' not on 'wallet'
|
2022-10-18 21:28:38 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
2024-03-15 01:50:34 +00:00
|
|
|
request, "walletsall.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions, "year": current_expo()}
|
2023-01-30 19:04:36 +00:00
|
|
|
)
|