mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
New wallet goes to next available slot now
This commit is contained in:
parent
1f5b56a593
commit
3c7661836c
@ -22,7 +22,7 @@ from .auth import login_required_if_public
|
||||
todo = """
|
||||
- Register uploaded filenames in the Django db without needing to wait for a reset & bulk file import
|
||||
|
||||
- Need to validate uploaded file as being a valid image file, not a dubious script or hack
|
||||
- Need to validate uploaded file as being a valid file type, not a dubious script or hack
|
||||
|
||||
- Write equivalent GPX upload form system, similar to walletedit() but in expofiles/gpslogs/
|
||||
Need to validate it as being a valid GPX file using an XML parser, not a dubious script or hack
|
||||
|
@ -27,9 +27,7 @@ from troggle.core.views.uploads import FilesForm
|
||||
from troggle.parsers.scans import contentsjson
|
||||
|
||||
|
||||
# from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
|
||||
|
||||
"""File upload 'views'
|
||||
"""Main wallet editing form, which includes scan file upload into the wallet
|
||||
"""
|
||||
|
||||
todo = """
|
||||
@ -38,17 +36,6 @@ todo = """
|
||||
- Refactor walletedit() as it contains all the wallets 'complaints' code from the old script wallets.py
|
||||
|
||||
- Need to validate uploaded file as being a valid image file, not a dubious script or hack
|
||||
|
||||
- Write equivalent GPX upload form system, similar to walletedit() but in expofiles/gpslogs/
|
||||
Need to validate it as being a valid GPX file using an XML parser, not a dubious script or hack
|
||||
|
||||
- Validate Tunnel & Therion files using an XML parser in dwgupload(). Though Julian says tunnel is only mostly correct XML
|
||||
|
||||
- Validate image files using a magic recogniser in walletedit() https://pypi.org/project/reportlab/ or
|
||||
https://stackoverflow.com/questions/889333/how-to-check-if-a-file-is-a-valid-image-file
|
||||
|
||||
- Enable folder creation in dwguploads or as a separate form
|
||||
|
||||
"""
|
||||
WALLET_BLANK_JSON = {
|
||||
"cave": "",
|
||||
@ -277,8 +264,7 @@ def walletedit(request, path=None):
|
||||
You will find the Django documentation on forms very confusing,
|
||||
as it covers many very differnet things we do not need. This is simpler.
|
||||
|
||||
This subsumes much of the code which was in the old wallets.py script and so this function is very long
|
||||
indeed and needs refactoring.
|
||||
This subsumes much of the code which was in the old wallets.py script and so this function is very long indeed and needs refactoring.
|
||||
|
||||
REWRITE bits using the ticklist, dateify, caveify, populate etc utility functions in core.view.scans.py
|
||||
"""
|
||||
@ -286,6 +272,54 @@ def walletedit(request, path=None):
|
||||
filesaved = False
|
||||
actual_saved = []
|
||||
|
||||
def get_next_empty():
|
||||
latest = Wallet.objects.filter(walletname__startswith="20").latest('walletname')
|
||||
print(f"Latest {latest=}")
|
||||
next = int(latest.walletname[5:]) + 1
|
||||
return f"{latest.walletname[:4]}:{next:02d}"
|
||||
|
||||
def preprocess_path(path):
|
||||
if path:
|
||||
wpath = urllib.parse.unquote(path)
|
||||
else:
|
||||
return (None, get_next_empty() )
|
||||
|
||||
try:
|
||||
year = wpath[:4] # if path too short, exception catches it
|
||||
sepr = wpath[4]
|
||||
y = int(year) # exception catches non-integer [:4]
|
||||
wnumber = int(wpath[5:]) # exception catches nonumeric wallet number
|
||||
if sepr != "#" and sepr != ":":
|
||||
return (oldwallet(request, path), None)
|
||||
except:
|
||||
# if nonumeric wpath name for example
|
||||
raise
|
||||
return (oldwallet(request, path), None)
|
||||
|
||||
if not re.match("(19|20)\d\d[:#]\d\d\d?", wpath):
|
||||
return (None, get_next_empty() )
|
||||
|
||||
if int(year) < 1977:
|
||||
year = "1977"
|
||||
if int(year) > 2050:
|
||||
year = "2050"
|
||||
wallet = f"{year}:{wnumber:02d}"
|
||||
return (None, wallet)
|
||||
|
||||
def create_nav_links(wallet):
|
||||
print(f" --- {wallet}")
|
||||
y = wallet[:4]
|
||||
n = wallet[5:]
|
||||
nexty = f"{int(y)+1}"
|
||||
prevy = f"{int(y)-1}"
|
||||
next = f"{int(n)+1:02d}"
|
||||
prev = f"{int(n)-1:02d}"
|
||||
|
||||
if int(n) == 0:
|
||||
prev = f"{int(n):02d}"
|
||||
|
||||
return next, nexty, prev, prevy, y
|
||||
|
||||
def read_json():
|
||||
"""Read JSON from the wallet metadata file in the repo
|
||||
or fills with blank data if that files can't be read
|
||||
@ -405,45 +439,12 @@ def walletedit(request, path=None):
|
||||
"elev drawn",
|
||||
"electronic survey",
|
||||
]
|
||||
if path:
|
||||
wallet = urllib.parse.unquote(path)
|
||||
else:
|
||||
wallet = "2022#00" # improve this later
|
||||
|
||||
year = wallet[:4]
|
||||
try:
|
||||
if wallet[4] != "#" and wallet[4] != ":":
|
||||
# print(f'! - FORM walletedit - {wallet[4]} unurlencoded {unquote(wallet)[4]}')
|
||||
# print(f'! - FORM walletedit - start {wallet} REDIRECT TO OLDWALLET')
|
||||
return oldwallet(request, path)
|
||||
except:
|
||||
# if nonumeric wallet name for example
|
||||
return oldwallet(request, path)
|
||||
|
||||
if str(wallet).lower().endswith("indexpages"):
|
||||
# print(f'! - FORM walletedit - start {wallet} REDIRECT TO OLDWALLET')
|
||||
return walletindex(request, path)
|
||||
|
||||
if not re.match("(19|20)\d\d[:#]\d\d", wallet):
|
||||
wallet = "2022:00" # improve this later
|
||||
# print(f'! - FORM walletedit - start {wallet}')
|
||||
|
||||
if path:
|
||||
pass
|
||||
# print(f'! - FORM walletedit - start wallet:{wallet}: path:{path}:')
|
||||
if int(year) < 1977:
|
||||
year = "1977"
|
||||
if int(year) > 2050:
|
||||
year = "2050"
|
||||
nexty = f"{int(year)+1}"
|
||||
prevy = f"{int(year)-1}"
|
||||
|
||||
wnumber = wallet[5:]
|
||||
next = f"{int(wnumber)+1:02d}"
|
||||
prev = f"{int(wnumber)-1:02d}"
|
||||
|
||||
if int(wnumber) == 0:
|
||||
prev = f"{int(wnumber):02d}"
|
||||
redirect, wallet = preprocess_path(path)
|
||||
if redirect:
|
||||
return redirect
|
||||
print(f"{wallet=}")
|
||||
next, nexty, prev, prevy, year = create_nav_links(wallet)
|
||||
|
||||
wurl = f"/walletedit/{wallet}".replace("#", ":")
|
||||
wallet = wallet.replace(":", "#")
|
||||
@ -706,7 +707,13 @@ def walletedit(request, path=None):
|
||||
except:
|
||||
samedate = None
|
||||
|
||||
try:
|
||||
thisexpo = Expedition.objects.get(year=int(year))
|
||||
except: # creating a wallet for an expo that does not exist perhaps
|
||||
message = f"Trying to access an Expo for '{year}' which does not exist (yet)."
|
||||
message += " See /handbook/computing/newyear.html"
|
||||
print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
if samedate:
|
||||
svxothers = SurvexBlock.objects.filter(date=samedate)
|
||||
trips = LogbookEntry.objects.filter(date=samedate)
|
||||
|
@ -18,7 +18,7 @@
|
||||
<input
|
||||
label = "WalletGoto" name = "walletgoto" size="7"
|
||||
title="Wallet name to go to directly"
|
||||
placeholder="2022#nn" value="2022#" />
|
||||
placeholder="2023#nn" value="2023#" />
|
||||
|
||||
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user