summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-02-01 23:43:05 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-02-01 23:43:05 +0000
commit9d1c0ac395a5509d577cb030148e335b1ee2b5c8 (patch)
treef8eae57a56d9f54709d8df78c167afcce4c5fcf7 /parsers/survex.py
parentc7d88077ec06fd7141d2c90998c1547e946702ce (diff)
downloadtroggle-9d1c0ac395a5509d577cb030148e335b1ee2b5c8.tar.gz
troggle-9d1c0ac395a5509d577cb030148e335b1ee2b5c8.tar.bz2
troggle-9d1c0ac395a5509d577cb030148e335b1ee2b5c8.zip
Setting wallet dates earlier in the import process
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index d977296..8bde946 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -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}."