forked from expo/troggle
fixes for crashes,svx files in wallets
This commit is contained in:
parent
3af1112847
commit
dc2b8ad431
@ -281,19 +281,24 @@ class Wallet(models.Model):
|
|||||||
waldata["survex file"] = [waldata["survex file"]]
|
waldata["survex file"] = [waldata["survex file"]]
|
||||||
ngood = 0
|
ngood = 0
|
||||||
nbad = 0
|
nbad = 0
|
||||||
ticks["S"] = "black"
|
ticks["S"] = "purple"
|
||||||
for svx in waldata["survex file"]:
|
for sx in waldata["survex file"]:
|
||||||
if svx !="":
|
#this logic appears in several places, inc uploads.py). Refactor.
|
||||||
if (Path(settings.SURVEX_DATA) / svx).is_file():
|
if sx !="":
|
||||||
|
if Path(sx).suffix.lower() != ".svx":
|
||||||
|
sx = sx + ".svx"
|
||||||
|
if (Path(settings.SURVEX_DATA) / sx).is_file():
|
||||||
ngood += 1
|
ngood += 1
|
||||||
else:
|
else:
|
||||||
nbad += 1
|
nbad += 1
|
||||||
if nbad == 0 and ngood >= 1:
|
if nbad == 0 and ngood >= 1:
|
||||||
ticks["S"] = "green"
|
ticks["S"] = "green"
|
||||||
if nbad >= 1 and ngood >= 1:
|
elif nbad >= 1 and ngood >= 1:
|
||||||
ticks["S"] = "orange"
|
ticks["S"] = "orange"
|
||||||
if nbad >= 1 and ngood == 0:
|
elif nbad >= 1 and ngood == 0:
|
||||||
ticks["S"] = "red"
|
ticks["S"] = "red"
|
||||||
|
else:
|
||||||
|
ticks["S"] = "black"
|
||||||
|
|
||||||
# Cave Description
|
# Cave Description
|
||||||
if waldata["description written"]:
|
if waldata["description written"]:
|
||||||
|
@ -28,7 +28,7 @@ from troggle.parsers.scans import contentsjson
|
|||||||
from troggle.core.models.troggle import DataIssue
|
from troggle.core.models.troggle import DataIssue
|
||||||
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
||||||
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
|
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
|
||||||
from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock, SurvexFile
|
from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock, SurvexFile, SurvexPersonRole
|
||||||
from troggle.core.views.scans import oldwallet, walletindex
|
from troggle.core.views.scans import oldwallet, walletindex
|
||||||
from troggle.core.views.caves import getCave
|
from troggle.core.views.caves import getCave
|
||||||
|
|
||||||
@ -127,13 +127,12 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
|||||||
Loads the survex files names and processes all complaints
|
Loads the survex files names and processes all complaints
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# If skipping through the wllets on the upload form, the wallet may not yet exist
|
# If skipping through the wallets on the upload form, the wallet may not yet exist
|
||||||
try:
|
try:
|
||||||
w = Wallet.objects.get(walletname=wallet)
|
w = Wallet.objects.get(walletname=wallet)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
ticks = w.get_ticks()
|
|
||||||
|
|
||||||
# Date
|
# Date
|
||||||
if not waldata["date"]:
|
if not waldata["date"]:
|
||||||
@ -150,6 +149,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
|||||||
if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way
|
if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way
|
||||||
waldata["survex file"] = [waldata["survex file"]]
|
waldata["survex file"] = [waldata["survex file"]]
|
||||||
for sx in waldata["survex file"]:
|
for sx in waldata["survex file"]:
|
||||||
|
#this logic appears in several places, inc get_ticks(). Refactor.
|
||||||
if sx !="":
|
if sx !="":
|
||||||
if Path(sx).suffix.lower() != ".svx":
|
if Path(sx).suffix.lower() != ".svx":
|
||||||
sx = sx + ".svx"
|
sx = sx + ".svx"
|
||||||
@ -168,6 +168,8 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
|||||||
if survex_complaint:
|
if survex_complaint:
|
||||||
complaints.append(survex_complaint)
|
complaints.append(survex_complaint)
|
||||||
|
|
||||||
|
ticks = w.get_ticks()
|
||||||
|
|
||||||
|
|
||||||
# Notes required
|
# Notes required
|
||||||
if ticks['N'] != "green":
|
if ticks['N'] != "green":
|
||||||
@ -242,6 +244,7 @@ def scanupload(request, path=None):
|
|||||||
def read_json():
|
def read_json():
|
||||||
'''Read JSON from the wallet metadata file in the repo
|
'''Read JSON from the wallet metadata file in the repo
|
||||||
or fills with blank data if that files can't be read'''
|
or fills with blank data if that files can't be read'''
|
||||||
|
waldata = {}
|
||||||
if contents_path.is_file():
|
if contents_path.is_file():
|
||||||
create = False # yes wallet exists because JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
|
create = False # yes wallet exists because JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
|
||||||
with open(contents_path) as json_file:
|
with open(contents_path) as json_file:
|
||||||
@ -256,11 +259,14 @@ def scanupload(request, path=None):
|
|||||||
print(f'--- No JSON exists, so creating blank copy')
|
print(f'--- No JSON exists, so creating blank copy')
|
||||||
waldata = WALLET_BLANK_JSON.copy()
|
waldata = WALLET_BLANK_JSON.copy()
|
||||||
if not waldata["survex file"]:
|
if not waldata["survex file"]:
|
||||||
w = Wallet.objects.get(walletname=wallet)
|
try:
|
||||||
b = SurvexBlock.objects.filter(scanswallet=w)
|
w = Wallet.objects.get(walletname=wallet)
|
||||||
waldata["survex file"] = []
|
b = SurvexBlock.objects.filter(scanswallet=w)
|
||||||
for bsf in b:
|
waldata["survex file"] = []
|
||||||
waldata["survex file"].append(bsf.survexfile.path)
|
for bsf in b:
|
||||||
|
waldata["survex file"].append(bsf.survexfile.path)
|
||||||
|
except:
|
||||||
|
print(f'--- No wallet {wallet} exists in database')
|
||||||
return waldata
|
return waldata
|
||||||
|
|
||||||
def save_json(jsondict):
|
def save_json(jsondict):
|
||||||
@ -446,7 +452,7 @@ def scanupload(request, path=None):
|
|||||||
dirs = []
|
dirs = []
|
||||||
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
|
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
|
||||||
if dirpath.is_dir():
|
if dirpath.is_dir():
|
||||||
create = False # wallet exists becausse folder exists, even if nothing in it
|
create = False # wallet exists because folder exists, even if nothing in it
|
||||||
try:
|
try:
|
||||||
for f in dirpath.iterdir():
|
for f in dirpath.iterdir():
|
||||||
if f.is_dir():
|
if f.is_dir():
|
||||||
@ -474,49 +480,103 @@ def scanupload(request, path=None):
|
|||||||
checked = {}
|
checked = {}
|
||||||
context = {}
|
context = {}
|
||||||
if waldata: # should always be true as populated by blank data if json file doesn't exist
|
if waldata: # should always be true as populated by blank data if json file doesn't exist
|
||||||
if not waldata["people"]:
|
|
||||||
waldata["people"]=["NOBODY"]
|
# if not type(waldata["people"])==list:
|
||||||
if not type(waldata["people"])==list:
|
# if waldata["people"][0] == '"':
|
||||||
if waldata["people"][0] == '"':
|
# waldata["people"] = waldata["people"][1:-1]
|
||||||
waldata["people"] = waldata["people"][1:-1]
|
# waldata["people"] = list(waldata["people"])
|
||||||
waldata["people"] = list(waldata["people"])
|
|
||||||
|
|
||||||
|
if not waldata["date"] or not waldata["people"] or waldata["people"] == ["Unknown"]: # json file does not exist, blank data, or people not typed into JSON file
|
||||||
|
# refactor into separate functions for no date set or no people set
|
||||||
|
# print(f'No date set')
|
||||||
|
print(f'\n - Incomplete or empty wallet data {wallet} {waldata=}')
|
||||||
|
refs=[]
|
||||||
|
dates = []
|
||||||
|
team = []
|
||||||
|
caverefs = []
|
||||||
|
caves =[]
|
||||||
|
names =[]
|
||||||
|
svxf = ''
|
||||||
|
if waldata["survex file"]:
|
||||||
|
if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way
|
||||||
|
waldata["survex file"] = [waldata["survex file"]]
|
||||||
|
for svxf in waldata["survex file"]:
|
||||||
|
print(f' - {svxf=}')
|
||||||
|
if svxf:
|
||||||
|
svx = Path(svxf)
|
||||||
|
if svx.suffix.lower() != ".svx":
|
||||||
|
svx = svx.with_suffix(".svx")
|
||||||
|
f = Path(settings.SURVEX_DATA) / svx
|
||||||
|
if f.is_file():
|
||||||
|
path = svx.parent / svx.stem
|
||||||
|
#print(f' - {path=}')
|
||||||
|
svxfile = SurvexFile.objects.get(path=path)
|
||||||
|
print(f' - {svxfile=}')
|
||||||
|
caves.append(svxfile.cave)
|
||||||
|
caverefs.append(svxfile.cave.reference())
|
||||||
|
blocks = SurvexBlock.objects.filter(survexfile= svxfile)
|
||||||
|
for b in blocks:
|
||||||
|
print(f' - - {b=} {b.scanswallet=} {b.date=}')
|
||||||
|
if b.scanswallet:
|
||||||
|
refs.append(b.scanswallet)
|
||||||
|
if b.scanswallet.walletname == wallet:
|
||||||
|
if b.date:
|
||||||
|
dates.append(b.date)
|
||||||
|
if b.name != b.title:
|
||||||
|
names.append(str(b.name) + "|" + str(b.title))
|
||||||
|
else:
|
||||||
|
names.append(str(b.name))
|
||||||
|
# we can use the people, across all blocks that have this *ref
|
||||||
|
QSpeople = SurvexPersonRole.objects.filter(survexblock=b)
|
||||||
|
print(f' - - {QSpeople=}')
|
||||||
|
for p in QSpeople:
|
||||||
|
team.append(p.personname)
|
||||||
|
# else:
|
||||||
|
# print(f' - Wallet not matching *ref {b.scanswallet=} {wallet}')
|
||||||
|
if dates:
|
||||||
|
waldata["date"] = min(dates).isoformat()
|
||||||
|
team = list(set(team))
|
||||||
|
waldata["people"] = team
|
||||||
|
|
||||||
|
caverefs = list(set(caverefs))
|
||||||
|
caves = list(set(caves))
|
||||||
|
|
||||||
|
if len(caverefs) == 1:
|
||||||
|
waldata["cave"] = caverefs[0]
|
||||||
|
print(f' - Setting wallet cave to {caverefs[0]}')
|
||||||
|
waldata["description url"] = caves[0]
|
||||||
|
elif len(caverefs) == 0:
|
||||||
|
waldata["cave"] = ""
|
||||||
|
waldata["description url"] = ""
|
||||||
|
print(f' - No caves in this wallet {wallet}. ')
|
||||||
|
else:
|
||||||
|
waldata["cave"] = "several caves"
|
||||||
|
waldata["description url"] = "several.."
|
||||||
|
print(f' - More than one Cave {caves} in this wallet {wallet}. Not managed in this troggle release.')
|
||||||
|
if len(names) == 1:
|
||||||
|
if waldata["name"] == '':
|
||||||
|
waldata["name"] = names[0]
|
||||||
|
print(f' - Setting wallet name to {names[0]}')
|
||||||
|
elif len(names) == 0:
|
||||||
|
waldata["name"] = ''
|
||||||
|
print(f' - Setting wallet name blank')
|
||||||
|
else:
|
||||||
|
waldata["name"] = f"several, please edit: {names}"
|
||||||
|
print(f' - More than one block name is relevant {names} in this wallet {wallet}. Not managed in this troggle release.')
|
||||||
|
|
||||||
if not waldata["description url"]:
|
|
||||||
waldata["description url"]=""
|
|
||||||
if waldata["cave"]:
|
if waldata["cave"]:
|
||||||
cave = waldata["cave"] # text string
|
cave = waldata["cave"] # text string
|
||||||
if waldata["name"]:
|
if waldata["name"]:
|
||||||
psg = waldata["name"]
|
psg = waldata["name"]
|
||||||
|
if not waldata["description url"]:
|
||||||
if not waldata["date"]: # json file does not exist, blank data
|
waldata["description url"]=""
|
||||||
# refactor into a separate function..
|
|
||||||
print(f'No date set')
|
|
||||||
refs=[]
|
|
||||||
dates = []
|
|
||||||
for svxf in waldata["survex file"]:
|
|
||||||
svx = Path(svxf)
|
|
||||||
if svx.suffix.lower() != ".svx":
|
|
||||||
svx = svx.with_suffix(".svx")
|
|
||||||
#print(f'{svx=}')
|
|
||||||
f = Path(settings.SURVEX_DATA) / svx
|
|
||||||
if f.is_file():
|
|
||||||
path = svx.parent / svx.stem
|
|
||||||
print(f' - {path=}')
|
|
||||||
svxfile = SurvexFile.objects.get(path=path)
|
|
||||||
blocks = SurvexBlock.objects.filter(survexfile= svxfile)
|
|
||||||
for b in blocks:
|
|
||||||
print(f' - - {b=} {b.scanswallet=} {b.date=}')
|
|
||||||
refs.append(b.scanswallet)
|
|
||||||
dates.append(b.date)
|
|
||||||
waldata["date"] = min(dates).isoformat()
|
|
||||||
for w in refs:
|
|
||||||
if w.walletname != wallet:
|
|
||||||
print(f'! Not the same wallet {wallet} in *ref {w.walletname=}')
|
|
||||||
|
|
||||||
#Survex and survex complaints
|
#Survex and survex complaints
|
||||||
complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl)
|
complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl)
|
||||||
|
# print(f' - {caveobject=}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for f in checkboxes:
|
for f in checkboxes:
|
||||||
if waldata[f]:
|
if waldata[f]:
|
||||||
checked[f] = "checked"
|
checked[f] = "checked"
|
||||||
@ -538,7 +598,7 @@ def scanupload(request, path=None):
|
|||||||
'url': waldata["description url"], 'urlsize': str(len(str(waldata["description url"]))),
|
'url': waldata["description url"], 'urlsize': str(len(str(waldata["description url"]))),
|
||||||
'survex': waldata["survex file"], 'survexsize': survexsize,
|
'survex': waldata["survex file"], 'survexsize': survexsize,
|
||||||
'cave': cave, 'psg': psg, 'psgsize': str(max(12,len(str(psg))))})
|
'cave': cave, 'psg': psg, 'psgsize': str(max(12,len(str(psg))))})
|
||||||
else: # no wallet here
|
else: # no wallet data: should never happen as their should be default data in all cases
|
||||||
context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty,
|
context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty,
|
||||||
'files': files, 'dirs': dirs, 'waldata': waldata, 'svxfiles': svxfiles,
|
'files': files, 'dirs': dirs, 'waldata': waldata, 'svxfiles': svxfiles,
|
||||||
'checked': checked,
|
'checked': checked,
|
||||||
|
@ -150,7 +150,7 @@
|
|||||||
title="Cave id e.g. 2017-DM-01 or 1623/256"
|
title="Cave id e.g. 2017-DM-01 or 1623/256"
|
||||||
placeholder="{{cave}}" value="{{cave}}" />
|
placeholder="{{cave}}" value="{{cave}}" />
|
||||||
<br>
|
<br>
|
||||||
<label for="psg">Survey area</label>
|
<label for="psg">Survey area (wallet name)</label>
|
||||||
<input
|
<input
|
||||||
label = "Survey area" name = "psg" size ="{{psgsize}}"
|
label = "Survey area" name = "psg" size ="{{psgsize}}"
|
||||||
title="Survey area, e.g. White Elephant or Nieder Augst Eck"
|
title="Survey area, e.g. White Elephant or Nieder Augst Eck"
|
||||||
@ -183,7 +183,7 @@
|
|||||||
<label for="electronic">Electronic survey ?</label>
|
<label for="electronic">Electronic survey ?</label>
|
||||||
<input type="checkbox" name="electronic" id="electronic" value="True" {% if "electronic survey" in checked %}checked{% endif %}>
|
<input type="checkbox" name="electronic" id="electronic" value="True" {% if "electronic survey" in checked %}checked{% endif %}>
|
||||||
<br>
|
<br>
|
||||||
<label for="people">List of people on the survey trip</label>
|
<label for="people">List of people on the survey trip(s)</label>
|
||||||
<input
|
<input
|
||||||
label = "People" name = "people" size ="{{peoplesize}}"
|
label = "People" name = "people" size ="{{peoplesize}}"
|
||||||
title="List of people on the survey trip"
|
title="List of people on the survey trip"
|
||||||
|
Loading…
Reference in New Issue
Block a user