forked from expo/troggle
make nav cope with missing wallets
This commit is contained in:
@@ -309,8 +309,47 @@ def walletedit(request, path=None):
|
||||
wallet = f"{year}:{wnumber:02d}"
|
||||
return (None, wallet)
|
||||
|
||||
def identify_most_recent_wallet(wallet, y):
|
||||
""" Need to find the last wallet of the previous year
|
||||
Has to cope with years when there are no wallets
|
||||
Has to cope with weirdly named imported wallets from 1999 & earlier
|
||||
Has to cope if the 'current' wallet is one that happens to 'not exist' too.
|
||||
|
||||
Frankly this has just become too bizarre and we should devise a quite different
|
||||
navigation system.
|
||||
"""
|
||||
current_name = wallet.replace(":","#")
|
||||
|
||||
try:
|
||||
allwallets = Wallet.objects.all().order_by('walletname')
|
||||
previous_wallet = allwallets.first()
|
||||
for w in allwallets:
|
||||
if len(w.walletname) < 5:
|
||||
continue
|
||||
if w.walletname[4] != "#":
|
||||
continue
|
||||
|
||||
if w.walletname == current_name:
|
||||
break
|
||||
if int(w.walletyear.year) >= int(y):
|
||||
break
|
||||
previous_wallet = w
|
||||
name = previous_wallet.walletname
|
||||
|
||||
y = name[:4]
|
||||
prevy = f"{int(y)-1}"
|
||||
n = name[5:]
|
||||
prev = f"{int(n):02d}"
|
||||
|
||||
except:
|
||||
raise
|
||||
prev = f"{int(n):02d}"
|
||||
|
||||
print(prev, prevy, y)
|
||||
return prev, prevy, y
|
||||
|
||||
def create_nav_links(wallet):
|
||||
print(f"--- {wallet} now current")
|
||||
"""Find the previous wallet and next wallet and create navigation shortcuts"""
|
||||
y = wallet[:4]
|
||||
n = wallet[5:]
|
||||
nexty = f"{int(y)+1}"
|
||||
@@ -318,9 +357,9 @@ def walletedit(request, path=None):
|
||||
next = f"{int(n)+1:02d}"
|
||||
prev = f"{int(n)-1:02d}"
|
||||
|
||||
if int(n) == 0:
|
||||
prev = f"{int(n):02d}"
|
||||
|
||||
if int(n) == 0:
|
||||
prev, prevy, y = identify_most_recent_wallet(wallet, y)
|
||||
|
||||
return next, nexty, prev, prevy, y
|
||||
|
||||
def read_json():
|
||||
@@ -339,7 +378,7 @@ def walletedit(request, path=None):
|
||||
DataIssue.objects.create(parser="scans", message=message, url=wurl) # set URL to this wallet folder
|
||||
raise
|
||||
else: # no JSON file exists
|
||||
print("--- No JSON exists, so creating blank copy")
|
||||
print("--- No JSON exists, so using default copy")
|
||||
waldata = WALLET_BLANK_JSON.copy()
|
||||
if not waldata["survex file"]:
|
||||
try:
|
||||
@@ -366,7 +405,7 @@ def walletedit(request, path=None):
|
||||
"""We need a wallet Object so that the django template stuff can find the files"""
|
||||
try:
|
||||
w, created = Wallet.objects.get_or_create(walletname=walletname)
|
||||
print(f"--- Wallet string {walletname}, wallet object {w} created new?: {created}")
|
||||
# print(f"--- Wallet string {walletname}, wallet object {w} created new?: {created}")
|
||||
if created:
|
||||
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
||||
w.save()
|
||||
@@ -755,7 +794,7 @@ def walletedit(request, path=None):
|
||||
caveifywallet(thiswallet)
|
||||
thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form
|
||||
# fixsurvextick(thiswallet, thiswallet.ticks)
|
||||
print(f"--- {wallet} {thiswallet} walletdate={thiswallet.walletdate} immediately before form render")
|
||||
# print(f"--- {wallet} {thiswallet} walletdate={thiswallet.walletdate} immediately before form render")
|
||||
except:
|
||||
thiswallet = None
|
||||
context = {
|
||||
|
||||
Reference in New Issue
Block a user