mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 00:27:07 +00:00
check slashes in dates in wallets
This commit is contained in:
@@ -18,10 +18,10 @@ from troggle.core.models.caves import get_cave_leniently
|
||||
|
||||
YEAR_RANGE = (1975, 2050)
|
||||
|
||||
def make_valid_date(date):
|
||||
def make_valid_date(walletname, date):
|
||||
"""Take whatever garbage some fool has typed in and try to make it into a valid ISO-format date
|
||||
"""
|
||||
datestr = date.replace(".", "-")
|
||||
datestr = date.replace(".", "-").replace("/", "-")
|
||||
try:
|
||||
samedate = datetime.date.fromisoformat(datestr)
|
||||
return samedate
|
||||
@@ -36,7 +36,7 @@ def make_valid_date(date):
|
||||
y = y + 2000
|
||||
try:
|
||||
samedate = datetime.date(y, m, d)
|
||||
print(f"- - Warning, not in ISO format. '{datestr=}' but we coped: {samedate.isoformat()} ")
|
||||
print(f"- - Warning, not in ISO format. '{datestr=}' but we tried to cope: {samedate.isoformat()} {walletname}")
|
||||
return samedate
|
||||
except:
|
||||
print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ")
|
||||
@@ -150,9 +150,14 @@ class Wallet(models.Model):
|
||||
|
||||
# :drawings: walletjson/2022/2022#01/contents.json
|
||||
# fpath = /mnt/d/EXPO/expofiles/surveyscans/1999/1999#02
|
||||
# This does not work if there are subdirectories in the surveyscan folder
|
||||
fp = Path(self.fpath)
|
||||
wname = fp.name
|
||||
wyear = fp.parent.name
|
||||
|
||||
if not int(wyear):
|
||||
message = f"! Subfolder detected?:\n {wyear=} (should be eg. '2023')\n {wname=} \n {self.fpath=}"
|
||||
print(message)
|
||||
wurl = self.get_url()
|
||||
|
||||
if len(wyear) != 4 or len(wname) !=6:
|
||||
@@ -180,7 +185,7 @@ class Wallet(models.Model):
|
||||
return None
|
||||
|
||||
if waldata["date"]:
|
||||
thisdate = make_valid_date(waldata["date"])
|
||||
thisdate = make_valid_date(self.walletname, waldata["date"])
|
||||
if thisdate:
|
||||
self.walletdate = thisdate
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user