mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-24 00:01:54 +00:00
next year auto for wallets
This commit is contained in:
parent
4c8a88d20c
commit
e1eb85969a
@ -101,6 +101,7 @@ def current_expo():
|
||||
u = User.objects.get(username='expo')
|
||||
u.current_year = year
|
||||
u.save()
|
||||
# print(f"---{year}---")
|
||||
return year
|
||||
else:
|
||||
return settings.EPOCH.year # this is 1970
|
||||
|
@ -137,22 +137,23 @@ def fillblankothers(w):
|
||||
# Is this not done when we scan for wallets when we create them in the first place ?
|
||||
# needs to be refactored into models/wallets.py anyway
|
||||
wcaveid = w.cave()
|
||||
if not wcaveid or wcaveid == "":
|
||||
if type(wcaveid) == list:
|
||||
for i in wcaveid:
|
||||
i = i.strip("' []\"")
|
||||
if is_cave(w,i):
|
||||
if wcaveid:
|
||||
if wcaveid == "":
|
||||
if type(wcaveid) == list:
|
||||
for i in wcaveid:
|
||||
i = i.strip("' []\"")
|
||||
if is_cave(w,i):
|
||||
w.caves.add(Gcavelookup[i])
|
||||
elif wcaveid.find(',') != -1:
|
||||
# it's a list of cave ids as a string
|
||||
ids = wcaveid.split(',')
|
||||
for i in ids:
|
||||
i = i.strip("' []\"")
|
||||
if is_cave(w,i):
|
||||
w.caves.add(Gcavelookup[i])
|
||||
else:
|
||||
if is_cave(w,wcaveid):
|
||||
w.caves.add(Gcavelookup[i])
|
||||
elif wcaveid.find(',') != -1:
|
||||
# it's a list of cave ids as a string
|
||||
ids = wcaveid.split(',')
|
||||
for i in ids:
|
||||
i = i.strip("' []\"")
|
||||
if is_cave(w,i):
|
||||
w.caves.add(Gcavelookup[i])
|
||||
else:
|
||||
if is_cave(w,wcaveid):
|
||||
w.caves.add(Gcavelookup[i])
|
||||
|
||||
|
||||
def fixsurvextick(w, ticks):
|
||||
|
@ -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
|
||||
@ -372,11 +397,12 @@ def walletedit(request, path=None):
|
||||
recent_year = recent_name[:4]
|
||||
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Simple Fileupload{% endblock %}
|
||||
{% block title %}Wallet upload{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user