Setting wallet dates earlier in the import process

This commit is contained in:
2023-02-01 23:43:05 +00:00
parent c7d88077ec
commit 9d1c0ac395
5 changed files with 49 additions and 34 deletions

View File

@@ -55,6 +55,33 @@ class SurvexLeg:
compass = 0.0
clino = 0.0
def datewallet(w, earliest):
"""Gets the date of the youngest survexblock associated with the wallet
REFACTOR this to do the whole date-getting task
Currently there is only one SurvexBlock, but this is in anticipation of
chnaging the schema to allow many.
"""
first = earliest
blocks = SurvexBlock.objects.filter(scanswallet=w) # only ONE I think ?!
for b in blocks:
if b.date:
if b.date < first:
first = b.date
if first == earliest:
# no date found
w.date = None
else:
w.date = first.isoformat()
return w.date
def set_walletdate(w):
earliest = datetime.now().date()
if not w.date(): # sets .walletdate as a side-effect if it gets it from JSON
d = datewallet(w, earliest) # Not in JSON, so checks all the survex blocks
w.walletdate = d
w.save()
def stash_data_issue(parser=None, message=None, url=None, sb=None):
"""Avoid hitting the database for error messages until the end of the import"""
global dataissues
@@ -848,6 +875,7 @@ class LoadingSurvex:
survexblock.save()
# This is where we should check that the wallet JSON contains a link to the survexfile
# and that the JSON date and walletdate are set correctly to the survexblock date.
set_walletdate(survexblock.scanswallet)
else:
perps = get_people_on_trip(survexblock)
message = f" ! Wallet *REF bad in '{survexblock.survexfile.path}' '{refscan}' NOT in database i.e. wallet does not exist {perps}."