mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-27 17:51:53 +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 = User.objects.get(username='expo')
|
||||||
u.current_year = year
|
u.current_year = year
|
||||||
u.save()
|
u.save()
|
||||||
|
# print(f"---{year}---")
|
||||||
return year
|
return year
|
||||||
else:
|
else:
|
||||||
return settings.EPOCH.year # this is 1970
|
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 ?
|
# 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
|
# needs to be refactored into models/wallets.py anyway
|
||||||
wcaveid = w.cave()
|
wcaveid = w.cave()
|
||||||
if not wcaveid or wcaveid == "":
|
if wcaveid:
|
||||||
if type(wcaveid) == list:
|
if wcaveid == "":
|
||||||
for i in wcaveid:
|
if type(wcaveid) == list:
|
||||||
i = i.strip("' []\"")
|
for i in wcaveid:
|
||||||
if is_cave(w,i):
|
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])
|
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):
|
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.scans import caveifywallet, oldwallet
|
||||||
from troggle.core.views.uploads import FilesForm
|
from troggle.core.views.uploads import FilesForm
|
||||||
|
|
||||||
|
from troggle.core.utils import current_expo
|
||||||
|
|
||||||
from troggle.parsers.scans import contentsjson
|
from troggle.parsers.scans import contentsjson
|
||||||
|
|
||||||
|
|
||||||
@ -306,16 +308,39 @@ def walletedit(request, path=None):
|
|||||||
|
|
||||||
def get_next_empty():
|
def get_next_empty():
|
||||||
"""Gets the next most number for a new wallet just after the most recent one in the
|
"""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"""
|
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')
|
|
||||||
|
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
|
next = int(latest.walletname[5:]) + 1
|
||||||
return f"{latest.walletname[:4]}:{next:02d}"
|
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):
|
def preprocess_path(path):
|
||||||
if path:
|
if path:
|
||||||
wpath = urllib.parse.unquote(path)
|
wpath = urllib.parse.unquote(path)
|
||||||
else:
|
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:
|
try:
|
||||||
year = wpath[:4] # if path too short, exception catches it
|
year = wpath[:4] # if path too short, exception catches it
|
||||||
@ -352,8 +377,8 @@ def walletedit(request, path=None):
|
|||||||
current_name = wallet.replace(":","#")
|
current_name = wallet.replace(":","#")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
allwallets = Wallet.objects.all().order_by('walletname')
|
recent_wallet = get_last_wallet()
|
||||||
recent_wallet = allwallets.first()
|
allwallets = Wallet.objects.all().order_by('walletyear')
|
||||||
for w in allwallets:
|
for w in allwallets:
|
||||||
if len(w.walletname) < 5:
|
if len(w.walletname) < 5:
|
||||||
continue
|
continue
|
||||||
@ -370,13 +395,14 @@ def walletedit(request, path=None):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
recent_year = recent_name[:4]
|
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
|
return recent_year, recent_number
|
||||||
|
|
||||||
def create_nav_links(wallet):
|
def create_nav_links(wallet):
|
||||||
"""Find the previous wallet and next wallet and create navigation shortcuts"""
|
"""Find the previous wallet and next wallet and create navigation shortcuts"""
|
||||||
|
#xx, yy = identify_most_recent_wallet(wallet, y)
|
||||||
y = wallet[:4]
|
y = wallet[:4]
|
||||||
n = wallet[5:]
|
n = wallet[5:]
|
||||||
|
|
||||||
@ -432,13 +458,16 @@ def walletedit(request, path=None):
|
|||||||
json.dump(jsondict, jfile, indent=1)
|
json.dump(jsondict, jfile, indent=1)
|
||||||
# print(f'--- FINISHED saving to JSON at {contents_path}')
|
# 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
|
"""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
|
BUT we must restrict this to logged-in users otherwise spiderbots get at
|
||||||
the hidden Submit button and create zillions of the buggers"""
|
the hidden Submit button and create zillions of the buggers"""
|
||||||
|
# print(f"Making new wallet {walletname}")
|
||||||
try:
|
try:
|
||||||
w, created = Wallet.objects.get_or_create(walletname=walletname)
|
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 date:
|
||||||
|
w.walletdate = datetime.datetime.now()
|
||||||
if created:
|
if created:
|
||||||
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
||||||
_ = w.year() # sets the walletyear property as a side-effect
|
_ = w.year() # sets the walletyear property as a side-effect
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}Simple Fileupload{% endblock %}
|
{% block title %}Wallet upload{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user