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. QM page for {{ cave_id|safe }} {% endif %} -
Note that names in italics are copied from the related survex file block name.
Total underground survey length: {{length_ug|floatformat:"1g"}} m
-Note that this is for all the wallets listed above, which includes those which may not be directly relevant to what you are looking for.
+Note that this is for all the wallets listed above, which includes those which are surveys of different caves not just {{cave}}.
+
+If you want accurate cave lengths for {{cave}}, go to the primary survex file for this cave
+and click on the "Run 'cavern' on this SVX file" button at the bottom of the page.
Wallet | Wallet Date | Wallet Name | People | Scans | Survex blocks | Drawings using these scans |
---|