summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/models/caves.py14
-rw-r--r--core/models/wallets.py7
-rw-r--r--core/views/caves.py20
-rw-r--r--templates/cave.html11
-rw-r--r--templates/cavewallets.html7
5 files changed, 40 insertions, 19 deletions
diff --git a/core/models/caves.py b/core/models/caves.py
index 3193f2b..b3f6dfe 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -62,6 +62,20 @@ class CaveAndEntrance(models.Model):
# class CaveSlug(models.Model):
# moved to models/logbooks.py to avoid cyclic import problem. No I don't know why either.
+def get_cave_leniently(caveid):
+ try:
+ c = getCave(caveid)
+ if c:
+ return c
+ except:
+ # print(f"get_cave_leniently FAIL {caveid}")
+ try:
+ c = getCave("1623-"+caveid)
+ if c:
+ return c
+ except:
+ return None
+
class Cave(TroggleModel):
# (far) too much here perhaps,
areacode = models.CharField(max_length=4, blank=True, null=True) # could use models.IntegerChoices
diff --git a/core/models/wallets.py b/core/models/wallets.py
index 3078e2d..0382adb 100644
--- a/core/models/wallets.py
+++ b/core/models/wallets.py
@@ -11,7 +11,7 @@ from django.db import models
from django.urls import reverse
from troggle.core.models.troggle import DataIssue
-from troggle.core.views.caves import get_cave_leniently
+from troggle.core.models.caves import get_cave_leniently
# from troggle.core.models.survex import SurvexBlock
# from troggle.core.models.troggle import DataIssue # circular import. Hmm
@@ -133,6 +133,9 @@ class Wallet(models.Model):
# we do not use URL_ROOT any more.
return reverse("singlewallet", kwargs={"path": re.sub("#", "%23", self.walletname)})
+ def get_url(self):
+ return f"/walletedit/{self.walletname}".replace('#', ':')
+
def get_json(self):
"""Read the JSON file for the wallet and do stuff
Do it every time it is queried, to be sure the result is fresh.. well, no.
@@ -150,7 +153,7 @@ class Wallet(models.Model):
fp = Path(self.fpath)
wname = fp.name
wyear = fp.parent.name
- wurl = f"/walletedit/{self.walletname}".replace('#', ':')
+ wurl = self.get_url()
if len(wyear) != 4 or len(wname) !=6:
# no contents.json for old-style wallets
diff --git a/core/views/caves.py b/core/views/caves.py
index 0811567..d71749c 100644
--- a/core/views/caves.py
+++ b/core/views/caves.py
@@ -15,8 +15,9 @@ from django.urls import NoReverseMatch, reverse
import troggle.settings as settings
from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm
-from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup
+from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup, get_cave_leniently
from troggle.core.models.logbooks import CaveSlug, QM
+from troggle.core.models.wallets import Wallet
from troggle.core.utils import write_and_commit
from troggle.core.views import expo
from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS
@@ -40,19 +41,7 @@ todo = """
https://zerotobyte.com/how-to-use-django-select-related-and-prefetch-related/
"""
-def get_cave_leniently(caveid):
- try:
- c = getCave(caveid)
- if c:
- return c
- except:
- # print(f"get_cave_leniently FAIL {caveid}")
- try:
- c = getCave("1623-"+caveid)
- if c:
- return c
- except:
- return None
+
def getCaves(cave_id):
@@ -294,6 +283,8 @@ def rendercave(request, cave, slug, cave_id=""):
# see design docum in troggle/templates/cave.html
# see rendercave() in troggle/core/views/caves.py
templatefile = "cave.html"
+
+ wallets = Wallet.objects.filter(caves=cave)
if not cave_id:
cave_id = slug # cave.unofficial_number
@@ -305,6 +296,7 @@ def rendercave(request, cave, slug, cave_id=""):
"cave_id": cave_id,
"svxstem": str(svxstem),
"svx3d": svx3d,
+ "wallets": wallets,
}
# Do not catch any exceptions here: propagate up to caller
diff --git a/templates/cave.html b/templates/cave.html
index 81357a1..dd1155a 100644
--- a/templates/cave.html
+++ b/templates/cave.html
@@ -121,8 +121,15 @@ Nope, it is not useful, removing it... Philip S.
<a href="{% url 'caveQMs' cave_id|safe %}">QM page for {{ cave_id|safe }}</a>
{% endif %}
- <h2>Scanned survey notes</h2>
- <a href="{% url "cavewallets" cave_id %}">{{ cave_id|safe }}</a> (if any)
+ {% if wallets %}
+ <h2>Wallets: scanned survey notes</h2>
+
+ There are <a href="{% url "cavewallets" cave_id %}">{{wallets|length}} wallets</a> with data for this cave:<br />
+ {% for w in wallets %}
+
+ <a href="{{w.get_url}}">{{w.walletname}}</a>
+ {% endfor %}
+ {% endif %}
{% endif %}
{% if cave.notes %}
diff --git a/templates/cavewallets.html b/templates/cavewallets.html
index 771083b..82e0891 100644
--- a/templates/cavewallets.html
+++ b/templates/cavewallets.html
@@ -20,11 +20,16 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
{% for otherexpedition in expeditions %}
| <a <a href="/wallets/year/{{ otherexpedition.year }}">{{otherexpedition.year}}</a>
{% endfor %}</ul></ul>
+
{% include 'wallet_table.html' %}
+
<p>Note that names in italics are copied from the related survex file block name.
<br />
<p>Total underground survey length: {{length_ug|floatformat:"1g"}} m<br />
-Note that this is for <em>all the wallets</em> listed above, which includes those which may not be directly relevant to what you are looking for.
+Note that this is for <em>all the wallets</em> listed above, which includes those which are surveys of different caves not just {{cave}}.
+<br />
+If you want accurate cave lengths for {{cave}}, go to the <a href="/survexfile/{{cave.survex_file}}">primary survex file</a> for this cave
+and click on the "Run 'cavern' on this SVX file" button at the bottom of the page.
<br />
<table width=95%>
<tr><th>Wallet</th><th width=13%>Wallet Date</th><th>Wallet Name</th><th width=25%>People</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr>