forked from expo/troggle
make nav cope with missing wallets
This commit is contained in:
parent
5ae37eef82
commit
5798e8dcd5
@ -309,8 +309,47 @@ def walletedit(request, path=None):
|
|||||||
wallet = f"{year}:{wnumber:02d}"
|
wallet = f"{year}:{wnumber:02d}"
|
||||||
return (None, wallet)
|
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):
|
def create_nav_links(wallet):
|
||||||
print(f"--- {wallet} now current")
|
"""Find the previous wallet and next wallet and create navigation shortcuts"""
|
||||||
y = wallet[:4]
|
y = wallet[:4]
|
||||||
n = wallet[5:]
|
n = wallet[5:]
|
||||||
nexty = f"{int(y)+1}"
|
nexty = f"{int(y)+1}"
|
||||||
@ -318,9 +357,9 @@ def walletedit(request, path=None):
|
|||||||
next = f"{int(n)+1:02d}"
|
next = f"{int(n)+1:02d}"
|
||||||
prev = f"{int(n)-1:02d}"
|
prev = f"{int(n)-1:02d}"
|
||||||
|
|
||||||
if int(n) == 0:
|
if int(n) == 0:
|
||||||
prev = f"{int(n):02d}"
|
prev, prevy, y = identify_most_recent_wallet(wallet, y)
|
||||||
|
|
||||||
return next, nexty, prev, prevy, y
|
return next, nexty, prev, prevy, y
|
||||||
|
|
||||||
def read_json():
|
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
|
DataIssue.objects.create(parser="scans", message=message, url=wurl) # set URL to this wallet folder
|
||||||
raise
|
raise
|
||||||
else: # no JSON file exists
|
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()
|
waldata = WALLET_BLANK_JSON.copy()
|
||||||
if not waldata["survex file"]:
|
if not waldata["survex file"]:
|
||||||
try:
|
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"""
|
"""We need a wallet Object so that the django template stuff can find the files"""
|
||||||
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 created:
|
if created:
|
||||||
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
||||||
w.save()
|
w.save()
|
||||||
@ -755,7 +794,7 @@ def walletedit(request, path=None):
|
|||||||
caveifywallet(thiswallet)
|
caveifywallet(thiswallet)
|
||||||
thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form
|
thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form
|
||||||
# fixsurvextick(thiswallet, thiswallet.ticks)
|
# 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:
|
except:
|
||||||
thiswallet = None
|
thiswallet = None
|
||||||
context = {
|
context = {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<a href="/survexfile/">Survex</a> |
|
<a href="/survexfile/">Survex</a> |
|
||||||
<a href="{% url "survexcaveslist" %}">All Survex</a> |
|
<a href="{% url "survexcaveslist" %}">All Survex</a> |
|
||||||
<a href="{% url "allscans" %}">Scans</a> |
|
<a href="{% url "allscans" %}">Scans</a> |
|
||||||
<a href="{% url "walletedit" '0000:01' %}">Upload Scans</a> |
|
<a href="{% url "walletedit" '/' %}">Upload Scans</a> |
|
||||||
<a href="{% url "dwgallfiles" %}">Drawings</a> |
|
<a href="{% url "dwgallfiles" %}">Drawings</a> |
|
||||||
<a href="{% url "dwgupload" %}">Upload Drawings</a> |
|
<a href="{% url "dwgupload" %}">Upload Drawings</a> |
|
||||||
<a href="{% url "photoupload" %}">Upload Photos</a> |
|
<a href="{% url "photoupload" %}">Upload Photos</a> |
|
||||||
|
@ -6,7 +6,7 @@ Upload the survexfile using e.g.
|
|||||||
(for a survex file for cave 1623-290). You will cut and paste the survex file data into the window on the form.
|
(for a survex file for cave 1623-290). You will cut and paste the survex file data into the window on the form.
|
||||||
|
|
||||||
|
|
||||||
<p>While still logged-in, go to this page <a href="/walletedit/0000:00">Create Wallet</a> which will take you to the next unused wallet number page, and click the 'Create' button. This will not actually complete
|
<p>While still logged-in, go to this page <a href="/walletedit/">Create Wallet</a> which will take you to the next unused wallet number page, and click the 'Create' button. This will not actually complete
|
||||||
the creation of the wallet until you have also set the date for the wallet in the wallet edit form (which will appear when you press 'Create').
|
the creation of the wallet until you have also set the date for the wallet in the wallet edit form (which will appear when you press 'Create').
|
||||||
<p>
|
<p>
|
||||||
While editing the wallet you should enter in the form the url of the survexfile which you have just created at e.g. <a href="/survexfile/caves-1623/290/mynewsurvex.svx">/survexfile/caves-1623/290/mynewsurvex.svx</a> (see above).
|
While editing the wallet you should enter in the form the url of the survexfile which you have just created at e.g. <a href="/survexfile/caves-1623/290/mynewsurvex.svx">/survexfile/caves-1623/290/mynewsurvex.svx</a> (see above).
|
||||||
|
@ -5,7 +5,13 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% if user.username %}
|
{% if user.username %}
|
||||||
<h2>Wallet {{wallet}} - edit settings or upload a file</h2>
|
{% if not create %}
|
||||||
|
<h2>Wallet {{wallet}} - edit settings or upload a file</h2>
|
||||||
|
{% else %}
|
||||||
|
<h2>Wallet {{wallet}} - Create a new Wallet</h2>
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<h2>Wallet {{wallet}}</h2>
|
<h2>Wallet {{wallet}}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -63,24 +69,27 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>
|
{% if not create %}
|
||||||
{% for f in files %}
|
<p>
|
||||||
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{f}}">{{ f}}</a><br />
|
{% for f in files %}
|
||||||
{% empty %}
|
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{f}}">{{ f}}</a><br />
|
||||||
<p><No files in this wallet. >
|
{% empty %}
|
||||||
|
<p><No files in this wallet. >
|
||||||
{% endfor %}
|
|
||||||
<ul>
|
{% endfor %}
|
||||||
{% for d in dirs %}
|
<ul>
|
||||||
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{d}}"><em>{{d}}</em></a><br />
|
{% for d in dirs %}
|
||||||
{% endfor %}
|
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{d}}"><em>{{d}}</em></a><br />
|
||||||
</ul>
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
{% if create %}
|
{% if create %}
|
||||||
This online wallet does not yet exist.
|
This online wallet does not yet exist.
|
||||||
{% if user.username %}
|
{% if user.username %}
|
||||||
<br><br>It will be created when you click the Create button, <em>and then edit the date in the form below and save it</em>.
|
<br><br>It will be created when you click the Create button, <em>and then edit the date in the form and save it</em>.
|
||||||
{% else %}
|
{% else %}
|
||||||
<br><br>To create a wallet, you need to <a href=/accounts/login/>Log In </a> first and then return to this page.
|
<br><br>To create a wallet, you need to <a href=/accounts/login/>Log In </a> first and then return to this page.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
2
urls.py
2
urls.py
@ -87,7 +87,7 @@ trogglepatterns = [
|
|||||||
re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls
|
re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls
|
||||||
|
|
||||||
# Uploads - uploading a file
|
# Uploads - uploading a file
|
||||||
path('walletedit/', walletedit, name='walletedit'), # path=2020#01
|
path('walletedit/', walletedit, name='walletedit'),
|
||||||
path('walletedit/<path:path>', walletedit, name='walletedit'), # path=2020#01
|
path('walletedit/<path:path>', walletedit, name='walletedit'), # path=2020#01
|
||||||
path('photoupload/', photoupload, name='photoupload'), # restricted to current year
|
path('photoupload/', photoupload, name='photoupload'), # restricted to current year
|
||||||
path('photoupload/<path:folder>', photoupload, name='photoupload'), # restricted to current year
|
path('photoupload/<path:folder>', photoupload, name='photoupload'), # restricted to current year
|
||||||
|
Loading…
Reference in New Issue
Block a user