fix wallet date from survexfile

This commit is contained in:
Philip Sargent 2022-08-30 20:46:17 +03:00
parent 0853bbdd19
commit 3af1112847
2 changed files with 31 additions and 5 deletions

View File

@ -54,7 +54,7 @@ def datewallet(w, earliest):
# no date found
w.date = None
else:
w.date = first
w.date = first.isoformat()
def caveifywallet(w):
'''Gets the cave from the list of survex files,

View File

@ -28,7 +28,7 @@ from troggle.parsers.scans import contentsjson
from troggle.core.models.troggle import DataIssue
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock
from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock, SurvexFile
from troggle.core.views.scans import oldwallet, walletindex
from troggle.core.views.caves import getCave
@ -240,8 +240,10 @@ def scanupload(request, path=None):
actual_saved = []
def read_json():
'''Read JSON from the wallet metadata file in the repo
or fills with blank data if that files can't be read'''
if contents_path.is_file():
create = False # yes wallet exists becaue 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:
try:
waldata = json.load(json_file)
@ -471,9 +473,9 @@ def scanupload(request, path=None):
svxfiles = []
checked = {}
context = {}
if waldata:
if waldata: # should always be true as populated by blank data if json file doesn't exist
if not waldata["people"]:
waldata["people"]=["NOBODY", "someone"]
waldata["people"]=["NOBODY"]
if not type(waldata["people"])==list:
if waldata["people"][0] == '"':
waldata["people"] = waldata["people"][1:-1]
@ -486,6 +488,30 @@ def scanupload(request, path=None):
if waldata["name"]:
psg = waldata["name"]
if not waldata["date"]: # json file does not exist, blank data
# 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
complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl)