summaryrefslogtreecommitdiffstats
path: root/core/views/wallets_edit.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-03-14 23:59:39 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2024-03-14 23:59:39 +0000
commite1eb85969ae04fd457e8a3f21284488a348eb1f0 (patch)
tree81f213274d830b091f884aaa882291b6d97e1210 /core/views/wallets_edit.py
parent4c8a88d20cf54a70bd000fd8b7c5772118d2309a (diff)
downloadtroggle-e1eb85969ae04fd457e8a3f21284488a348eb1f0.tar.gz
troggle-e1eb85969ae04fd457e8a3f21284488a348eb1f0.tar.bz2
troggle-e1eb85969ae04fd457e8a3f21284488a348eb1f0.zip
next year auto for wallets
Diffstat (limited to 'core/views/wallets_edit.py')
-rw-r--r--core/views/wallets_edit.py47
1 files changed, 38 insertions, 9 deletions
diff --git a/core/views/wallets_edit.py b/core/views/wallets_edit.py
index 541048d..c863dce 100644
--- a/core/views/wallets_edit.py
+++ b/core/views/wallets_edit.py
@@ -27,6 +27,8 @@ from troggle.core.views.caves import getCave, get_cave_leniently
from troggle.core.views.scans import caveifywallet, oldwallet
from troggle.core.views.uploads import FilesForm
+from troggle.core.utils import current_expo
+
from troggle.parsers.scans import contentsjson
@@ -306,16 +308,39 @@ def walletedit(request, path=None):
def get_next_empty():
"""Gets the next most number for a new wallet just after the most recent one in the
- db. But if it has no date set, then ignore it as it was only just created"""
- latest = Wallet.objects.filter(walletname__startswith="20",walletdate__isnull=False).latest('walletname')
+ db. But if it has no date set, then ignore it as it was only just created
+
+ This assumes we are still in the same year as the most wallet.
+ """
+ latest = Wallet.objects.filter(walletname__startswith="20",walletdate__isnull=False).latest('walletname') # last VALID wallet
+ # print(f"latest is {latest}")
next = int(latest.walletname[5:]) + 1
return f"{latest.walletname[:4]}:{next:02d}"
-
+
+ def get_last_wallet():
+ last = Wallet.objects.all().order_by('walletyear').last()
+ # print(f"last wallet {last}")
+ return last
+
+ def are_we_next_year():
+ recent_wallet = get_last_wallet()
+ recent_year = recent_wallet.walletname[:4]
+ current_year = current_expo()
+
+ return int(current_year) > int(recent_year)
+
def preprocess_path(path):
if path:
wpath = urllib.parse.unquote(path)
else:
- return (None, get_next_empty() )
+ # OK the url is "empty". Now we decide if we want to start the next year.
+ if are_we_next_year():
+ new_walletname = current_expo() + "#00"
+ # print(f"{new_walletname}")
+ make_wallet(new_walletname, date=True)
+ nx = get_next_empty()
+ # print(nx)
+ return (None, nx)
try:
year = wpath[:4] # if path too short, exception catches it
@@ -352,8 +377,8 @@ def walletedit(request, path=None):
current_name = wallet.replace(":","#")
try:
- allwallets = Wallet.objects.all().order_by('walletname')
- recent_wallet = allwallets.first()
+ recent_wallet = get_last_wallet()
+ allwallets = Wallet.objects.all().order_by('walletyear')
for w in allwallets:
if len(w.walletname) < 5:
continue
@@ -370,13 +395,14 @@ def walletedit(request, path=None):
raise
recent_year = recent_name[:4]
- recent_number = recent_name[5:]
+ recent_number = recent_name[5:]
- # print(f"---identify_most_recent_wallet: {recent_year=} {recent_number=}")
+ print(f"---identify_most_recent_wallet: {recent_year=} {recent_number=}")
return recent_year, recent_number
def create_nav_links(wallet):
"""Find the previous wallet and next wallet and create navigation shortcuts"""
+ #xx, yy = identify_most_recent_wallet(wallet, y)
y = wallet[:4]
n = wallet[5:]
@@ -432,13 +458,16 @@ def walletedit(request, path=None):
json.dump(jsondict, jfile, indent=1)
# print(f'--- FINISHED saving to JSON at {contents_path}')
- def make_wallet(walletname):
+ def make_wallet(walletname, date=False):
"""We need a wallet Object so that the django template stuff can find the files
BUT we must restrict this to logged-in users otherwise spiderbots get at
the hidden Submit button and create zillions of the buggers"""
+ # print(f"Making new wallet {walletname}")
try:
w, created = Wallet.objects.get_or_create(walletname=walletname)
# print(f"--- Wallet string {walletname}, wallet object {w} created new?: {created}")
+ if date:
+ w.walletdate = datetime.datetime.now()
if created:
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
_ = w.year() # sets the walletyear property as a side-effect