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-01-30 23:04:11 +00:00
|
|
|
from troggle.core.models.survex import SingleScan, SurvexBlock
|
|
|
|
from troggle.core.models.wallets import Wallet
|
2023-01-19 18:35:56 +00:00
|
|
|
from troggle.core.models.troggle import DataIssue, Expedition, Person
|
2021-05-03 20:36:29 +01:00
|
|
|
from troggle.core.views.expo import getmimetype
|
2023-02-01 23:43:05 +00:00
|
|
|
from troggle.parsers.survex import set_walletdate
|
2023-08-02 16:23:04 +01:00
|
|
|
from troggle.parsers.caves import add_cave_to_pending_list
|
2023-01-19 18:35:56 +00:00
|
|
|
|
2023-01-30 19:04:36 +00:00
|
|
|
# from troggle.parsers.people import GetPersonExpeditionNameLookup
|
|
|
|
# import parsers.surveys
|
2021-05-03 20:36:29 +01:00
|
|
|
|
2023-01-30 19:04:36 +00:00
|
|
|
"""one of these views serves files as binary blobs, and simply set the mime type based on the file extension,
|
2021-05-03 20:36:29 +01:00
|
|
|
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.
|
|
|
|
|
|
|
|
need to check if inavlid query string is invalid, or produces multiple replies
|
|
|
|
and render a user-friendly error page.
|
2022-07-30 23:02:02 +01: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.
|
2022-08-24 17:08:08 +01:00
|
|
|
|
|
|
|
TODO
|
|
|
|
cave for a wallet - just gets the last one, randomly. SHould make this a list or many:many ideally
|
|
|
|
|
|
|
|
add this file in to the todo list thinggy.
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
|
|
|
|
2022-07-27 21:22:46 +01:00
|
|
|
|
2022-07-29 18:55:19 +01:00
|
|
|
def populatewallet(w):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Copy survex data here just for display, not permanently
|
|
|
|
|
2022-09-20 00:36:40 +01:00
|
|
|
Only gets data from the survex file when it was parsed on import..
|
|
|
|
so doesn't work if there is no *ref value
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
2022-07-29 18:55:19 +01:00
|
|
|
survexpeople = []
|
2023-01-30 19:04:36 +00:00
|
|
|
blocks = SurvexBlock.objects.filter(scanswallet=w)
|
2022-07-29 18:55:19 +01:00
|
|
|
for b in blocks:
|
2023-01-30 19:04:36 +00:00
|
|
|
for personrole in b.survexpersonrole_set.all():
|
2022-07-29 18:55:19 +01:00
|
|
|
survexpeople.append(personrole.personname)
|
2023-01-30 19:04:36 +00:00
|
|
|
w.persons = list(set(survexpeople))
|
|
|
|
|
2022-07-29 18:55:19 +01:00
|
|
|
|
2023-02-01 23:43:05 +00:00
|
|
|
|
2022-07-29 18:55:19 +01:00
|
|
|
def caveifywallet(w):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Gets the cave from the list of survex files,
|
2022-08-01 13:55:20 +01:00
|
|
|
only selects one of them though. Only used for display.
|
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
|
|
|
|
if b.survexfile.cave:
|
2023-01-30 19:04:36 +00:00
|
|
|
w.caveobj = (
|
|
|
|
b.survexfile.cave
|
|
|
|
) # just gets the last one, randomly. SHould make this a list or many:many ideally
|
2022-09-21 23:37:25 +01:00
|
|
|
w.cave = w.caveobj
|
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-01-30 19:04:36 +00:00
|
|
|
# this isn't working..? why? Because it needs a *ref and an import
|
|
|
|
wp = w.people()
|
|
|
|
w.persons = wp
|
|
|
|
if not wp:
|
|
|
|
populatewallet(w)
|
|
|
|
else:
|
|
|
|
if len(wp) == 1:
|
|
|
|
# print(f' - {wp=}')
|
|
|
|
nobody = wp[0].lower()
|
|
|
|
if nobody == "unknown" or nobody == "nobody" or nobody == " " or nobody == "":
|
|
|
|
# print(f' - {wp=} {nobody=}')
|
|
|
|
populatewallet(w)
|
|
|
|
|
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()
|
|
|
|
id = id.strip("' []'")
|
|
|
|
if id in Gcavelookup:
|
|
|
|
return True
|
|
|
|
else:
|
2023-09-16 11:53:05 +01:00
|
|
|
# Historic wallets used just 2 or 3 digits and were all 1623 area. So, just for these wallets,
|
|
|
|
# assume it is 1623-xxx
|
|
|
|
if f"1623-{id}" in Gcavelookup:
|
|
|
|
print(f" - Should modify wallet {wallet} to us 1623- prefix for cave <{id}>")
|
|
|
|
Gcavelookup[id] = Gcavelookup[f"1623-{id}"] # restoring ambiguous alias
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
print(f" - Wallet {wallet} Failed to find cave object from id <{id}>")
|
|
|
|
if id.lower() != "unknown" and id != "":
|
|
|
|
print(f" - adding <{id}> to pendingcaves.txt list")
|
|
|
|
add_cave_to_pending_list(id, f"Wallet {wallet} - Could not find id <{id}>")
|
|
|
|
return False
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-12-20 00:07:55 +00:00
|
|
|
def fillblankothers(w):
|
2023-08-02 16:23:04 +01:00
|
|
|
"""This is on the way to having a many:many relationship between Caves and Wallets
|
|
|
|
"""
|
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()
|
|
|
|
|
|
|
|
wcaveid = w.cave()
|
|
|
|
if not wcaveid or wcaveid == "":
|
2022-08-01 13:55:20 +01:00
|
|
|
caveifywallet(w)
|
2022-09-21 23:37:25 +01:00
|
|
|
else:
|
2022-10-06 19:37:09 +01:00
|
|
|
if type(wcaveid) == list:
|
|
|
|
for i in wcaveid:
|
2023-08-02 16:23:04 +01:00
|
|
|
i = i.strip("' []'")
|
2023-09-16 11:53:05 +01:00
|
|
|
if is_cave(w,i):
|
2023-08-02 16:23:04 +01:00
|
|
|
w.caveobj = Gcavelookup[i] # just sets it to the last one found. nasty. bug waiting to happen
|
|
|
|
elif wcaveid.find(',') != -1:
|
|
|
|
# it's a list of cave ids as a string
|
|
|
|
ids = wcaveid.split(',')
|
|
|
|
for i in ids:
|
|
|
|
i = i.strip("' []'")
|
2023-09-16 11:53:05 +01:00
|
|
|
if is_cave(w,i):
|
2023-08-02 16:23:04 +01:00
|
|
|
w.caveobj = Gcavelookup[i] # just sets it to the last one found. nasty. bug waiting to happen
|
2022-09-21 23:37:25 +01:00
|
|
|
else:
|
2023-09-16 11:53:05 +01:00
|
|
|
if is_cave(w,wcaveid):
|
2023-08-02 16:23:04 +01:00
|
|
|
w.caveobj = Gcavelookup[wcaveid.strip("' []'")]
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-08-31 10:09:07 +01:00
|
|
|
|
2022-07-31 16:58:46 +01:00
|
|
|
def walletslistperson(request, first_name, last_name):
|
2023-01-30 19:04:36 +00:00
|
|
|
"""Page which displays a list of all the wallets for a specific person
|
2022-07-31 16:58:46 +01:00
|
|
|
HORRIBLE linear search through everything. Index and do SQL query properly
|
2023-01-30 19:04:36 +00:00
|
|
|
"""
|
2022-07-31 16:58:46 +01:00
|
|
|
# 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..
|
2023-01-30 19:04:36 +00:00
|
|
|
# GetPersonExpeditionNameLookup
|
2022-08-01 13:55:20 +01:00
|
|
|
def tickspersonwallet(p):
|
|
|
|
manywallets = []
|
|
|
|
wallets = Wallet.objects.all()
|
|
|
|
for w in wallets:
|
2023-01-30 19:04:36 +00:00
|
|
|
w.persons = w.people() # ephemeral attribute for web page
|
2022-08-01 13:55:20 +01:00
|
|
|
fillblankpeople(w)
|
|
|
|
if w.persons:
|
|
|
|
if p.fullname in w.persons:
|
|
|
|
manywallets.append(w)
|
|
|
|
fillblankothers(w)
|
2023-01-30 19:04:36 +00:00
|
|
|
w.ticks = w.get_ticks() # the complaints in colour form
|
2022-08-31 10:09:07 +01:00
|
|
|
fixsurvextick(w, w.ticks)
|
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-01-30 19:04:36 +00:00
|
|
|
|
2022-07-31 16:58:46 +01:00
|
|
|
try:
|
|
|
|
if last_name:
|
2023-01-30 19:04:36 +00:00
|
|
|
p = Person.objects.get(fullname=f"{first_name} {last_name}")
|
|
|
|
else:
|
2022-10-07 21:47:05 +01:00
|
|
|
# special Wookey-hack
|
2023-01-30 19:04:36 +00:00
|
|
|
p = Person.objects.get(first_name=f"{first_name}")
|
2022-07-31 16:58:46 +01:00
|
|
|
except:
|
2023-01-30 19:04:36 +00:00
|
|
|
# raise
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"errors/generic.html",
|
|
|
|
{"message": f'Unrecognised name of a expo person: "{first_name} {last_name}"'},
|
|
|
|
)
|
|
|
|
|
2022-08-01 13:55:20 +01:00
|
|
|
manywallets = tickspersonwallet(p)
|
2022-10-15 19:28:56 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2023-01-30 23:04:11 +00:00
|
|
|
print("--")
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"personwallets.html",
|
|
|
|
{"manywallets": manywallets, "settings": settings, "person": p, "expeditions": expeditions},
|
|
|
|
)
|
|
|
|
|
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 = []
|
2023-01-30 19:04:36 +00:00
|
|
|
wallets = Wallet.objects.filter(walletyear__year=year)
|
2022-08-01 13:55:20 +01:00
|
|
|
for w in wallets:
|
2022-12-20 00:07:55 +00:00
|
|
|
manywallets.append(w)
|
|
|
|
fillblankpeople(w)
|
|
|
|
fillblankothers(w)
|
2023-01-30 19:04:36 +00:00
|
|
|
w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc
|
2022-12-20 00:07:55 +00:00
|
|
|
fixsurvextick(w, w.ticks)
|
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"})
|
|
|
|
|
|
|
|
# return render(request, 'errors/generic.html', {'message': 'This page logic not implemented yet'})
|
|
|
|
|
2022-12-20 00:07:55 +00:00
|
|
|
year = str(year)
|
2022-08-01 13:55:20 +01:00
|
|
|
manywallets = ticksyearwallet(year)
|
2023-02-27 16:42:08 +00:00
|
|
|
expeditions = Expedition.objects.all() #bad Django style
|
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 23:04:11 +00:00
|
|
|
print("--")
|
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
|
|
|
|
2022-09-21 22:23:22 +01:00
|
|
|
# remove duplication. Sorting is done in the template
|
|
|
|
# But this only gets wallets which have survex files attached..
|
|
|
|
wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave))
|
2023-01-30 19:04:36 +00:00
|
|
|
|
2022-09-21 22:23:22 +01:00
|
|
|
# all the ones without a survexblock attached via a *ref, search for match in JSON
|
|
|
|
zilchwallets = set(Wallet.objects.exclude(survexblock__survexfile__cave=cave))
|
|
|
|
for z in zilchwallets:
|
2022-09-21 23:37:25 +01:00
|
|
|
zcaveid = z.cave()
|
|
|
|
if zcaveid:
|
2023-08-02 16:23:04 +01:00
|
|
|
cleanid = str(zcaveid).strip("' []'")
|
|
|
|
|
|
|
|
if cleanid.find(',') != -1:
|
|
|
|
# it's a list of cave ids
|
|
|
|
wurl = f"/walletedit/{z.walletname.replace('#',':')}"
|
|
|
|
message = f" ! In {z.walletname} we do not handle lists of cave ids yet '{cleanid}'"
|
|
|
|
print(message)
|
|
|
|
DataIssue.objects.update_or_create(parser="scans", message=message, url=wurl)
|
|
|
|
|
|
|
|
# it's a list of cave ids as a string. Identify any orphan caves hidden here
|
|
|
|
ids = cleanid.split(',')
|
|
|
|
for i in ids:
|
|
|
|
i = i.strip("' []'")
|
2023-09-16 11:53:05 +01:00
|
|
|
if is_cave(z,i):
|
2023-08-02 16:23:04 +01:00
|
|
|
fcave = Gcavelookup[i.strip("' []'")] # just sets it to the last one found. nasty. bug waiting to happen
|
|
|
|
|
|
|
|
elif cleanid in Gcavelookup:
|
2023-07-25 19:07:13 +01:00
|
|
|
fcave = Gcavelookup[cleanid]
|
2022-09-21 22:23:22 +01:00
|
|
|
if str(fcave.slug()) == caveid:
|
2022-09-21 23:37:25 +01:00
|
|
|
# print(f' - Found one ! {z.walletname=} {zcaveid=}')
|
2022-09-21 22:23:22 +01:00
|
|
|
wallets.add(z)
|
2023-09-10 00:06:38 +01:00
|
|
|
elif f"1623-{cleanid}" in Gcavelookup: # special hack for all the old wallets which are 1623
|
|
|
|
fcave = Gcavelookup[f"1623-{cleanid}"]
|
|
|
|
if str(fcave.slug()) == caveid:
|
|
|
|
# print(f' - Found one ! {z.walletname=} {zcaveid=}')
|
|
|
|
wallets.add(z)
|
2023-07-25 19:07:13 +01:00
|
|
|
elif cleanid in ['surface', 'unknown', '']:
|
|
|
|
message = f" ! In {z.walletname} ignore '{cleanid}' "
|
|
|
|
print(message)
|
|
|
|
pass
|
2022-09-21 22:23:22 +01:00
|
|
|
else:
|
2023-01-31 17:13:41 +00:00
|
|
|
wurl = f"/walletedit/{z.walletname.replace('#',':')}"
|
2023-08-02 16:23:04 +01:00
|
|
|
message = f" ! In {z.walletname} there is an unrecognised cave name '{cleanid}', adding to pending list."
|
2022-10-06 19:03:14 +01:00
|
|
|
print(message)
|
2023-01-30 19:04:36 +00:00
|
|
|
DataIssue.objects.update_or_create(parser="scans", message=message, url=wurl)
|
2023-09-10 00:06:38 +01:00
|
|
|
add_cave_to_pending_list(cleanid, f"an unrecognised cave name in {z.walletname}")
|
2022-07-29 18:55:19 +01:00
|
|
|
|
2022-09-21 22:23:22 +01:00
|
|
|
manywallets = list(set(wallets))
|
2022-07-29 18:55:19 +01:00
|
|
|
for w in manywallets:
|
2022-08-01 13:55:20 +01:00
|
|
|
fillblankpeople(w)
|
2023-01-30 19:04:36 +00:00
|
|
|
fillblankothers(w)
|
|
|
|
w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc
|
2022-08-31 10:09:07 +01:00
|
|
|
fixsurvextick(w, w.ticks)
|
2022-10-15 19:28:56 +01:00
|
|
|
expeditions = Expedition.objects.all()
|
2023-01-30 23:04:11 +00:00
|
|
|
print("--")
|
2023-01-30 19:04:36 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"cavewallets.html",
|
|
|
|
{"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions},
|
|
|
|
)
|
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))
|
|
|
|
return render(request, "wallet_old.html", {"wallet": wallet, "settings": settings})
|
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}' ."
|
|
|
|
return render(request, "errors/generic.html", {"message": message})
|
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(
|
|
|
|
request, "manywallets.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions}
|
|
|
|
)
|