From 959c358c0930eea51329b3feac5419bb5e55a8be Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 29 Jul 2025 17:08:36 +0200 Subject: [PATCH] undropped caves code -> GPX --- core/models/caves.py | 2 +- core/models/survex.py | 8 +++++- core/views/caves.py | 28 +++++++++++++++++++ .../cavesallindex - Copy.html:Zone.Identifier | 0 templates/cavesundropped.html | 3 +- templates/cavesundroppedgpx.html | 5 ++++ urls.py | 2 ++ 7 files changed, 45 insertions(+), 3 deletions(-) delete mode 100644 templates/cavesallindex - Copy.html:Zone.Identifier create mode 100644 templates/cavesundroppedgpx.html diff --git a/core/models/caves.py b/core/models/caves.py index 293b87f..8714305 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -302,7 +302,7 @@ class Entrance(TroggleModel): def other_location(self): return self.single(self.other_station) - + def find_location(self): r = {"": "To be entered ", "?": "To be confirmed:", "S": "", "L": "Lost:", "R": "Refindable:"}[self.findability] if self.tag_station: diff --git a/core/models/survex.py b/core/models/survex.py index 1d5e501..db1b9a9 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -113,7 +113,13 @@ class SurvexStation(models.Model): return diff_str, ref - + def gpx_location(s): # s == self + # 1857.90tunnocks + latitude, longitude = utmToLatLng(33, s.x, s.y, northernHemisphere=True) + if s.name: + return f'{s.z:0.0f}{s.name[5:]}\n' + else: + return "" def utmToLatLng(zone, easting, northing, northernHemisphere=True): # move this to utils.py ? diff --git a/core/views/caves.py b/core/views/caves.py index a415448..1008b7a 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -5,6 +5,7 @@ import tempfile import urllib import zipfile from pathlib import Path +from datetime import datetime, timezone import django from bs4 import BeautifulSoup @@ -20,6 +21,7 @@ from troggle.core.forms import CaveForm, EntranceForm, EntranceLetterForm # Cav from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup, get_cave_leniently from troggle.core.models.logbooks import QM from troggle.core.models.wallets import Wallet +from troggle.core.models.survex import SurvexStation from troggle.core.utils import ( get_cookie_max_age, WriteAndCommitError, @@ -205,6 +207,32 @@ def getnotablecaves(): print(notablecaves) return notablecaves +def caves_undropped_gpx(request): + caves1623 = Cave.objects.filter(areacode="1623",unexplored="True") + caves1626 = Cave.objects.filter(areacode="1626",unexplored="True") + + + allcaves = list(caves1623) + list(caves1626) + + ent_locations = [] + for cave in allcaves: + ces = CaveAndEntrance.objects.filter(cave=cave) + for ce in ces: + stations = SurvexStation.objects.filter(entrance=ce.entrance) + for station in stations: + if gpx := station.gpx_location(): + ent_locations.append(gpx) + + + return render( + request, + "cavesundroppedgpx.html", + + {"ent_locations": ent_locations, + "now" : datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), # GPX format and UTC timezone + "year": current_expo()}, + ) + def caves_undropped(request): caves1623 = list(Cave.objects.filter(areacode="1623",unexplored="True")) caves1626 = list(Cave.objects.filter(areacode="1626",unexplored="True")) diff --git a/templates/cavesallindex - Copy.html:Zone.Identifier b/templates/cavesallindex - Copy.html:Zone.Identifier deleted file mode 100644 index e69de29..0000000 diff --git a/templates/cavesundropped.html b/templates/cavesundropped.html index bea81d8..322750f 100644 --- a/templates/cavesundropped.html +++ b/templates/cavesundropped.html @@ -10,7 +10,8 @@

See All Caves for all the caves in areas 1623, 1626, 1624, 1627
-See Recent Caves for a full list of recent caves. +See Recent Caves for a full list of recent caves.
+Download Undropped GPX file (This is only the subset which are fully located.)

New Cave
diff --git a/templates/cavesundroppedgpx.html b/templates/cavesundroppedgpx.html new file mode 100644 index 0000000..2d17ff2 --- /dev/null +++ b/templates/cavesundroppedgpx.html @@ -0,0 +1,5 @@ + + +Expo undropped caves + +{% for e in ent_locations %}{{e|safe}}{% endfor %} diff --git a/urls.py b/urls.py index 0896187..8953e47 100644 --- a/urls.py +++ b/urls.py @@ -12,6 +12,7 @@ from troggle.core.views.caves import ( cave_debug, caves_recent, caves_undropped, + caves_undropped_gpx, cavesall, cavepage, caveQMs, @@ -161,6 +162,7 @@ trogglepatterns = [ path('caveslist', caveslist, name="caveslist"), path('caves_recent', caves_recent, name="caves_recent"), path('caves_undropped', caves_undropped, name="caves_undropped"), + path('caves_undropped_gpx', caves_undropped_gpx, name="caves_undropped_gpx"), path('entrances', entranceindex, name="entranceindex"), path('enttags', entrancetags, name="entrancetags"),