diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py
index a682870..96bfe6a 100644
--- a/core/views/cave_kataster.py
+++ b/core/views/cave_kataster.py
@@ -7,7 +7,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
import troggle.settings as settings
-
+#from troggle.core.models.caves import Entrance, Cave
from troggle.core.utils import (
COOKIE_MAX_AGE,
WriteAndCommitError,
@@ -27,23 +27,27 @@ def kataster(request, slug):
"""Create the page which analyses how to rename a cave and all the files from the unofficial_number
identifier, e.g. 1623-2023-mg-03 to the kataster number e.g. 1623-999
"""
- def do_file_finding():
+
+ def do_file_finding(knum):
global cavefilename, cave_data, entrance_data, loser_name, loser_data
+ mvscript = f"cd {settings.CAVEDESCRIPTIONS }\n"
cavefilename = str(cave) + ".html"
cave_data = Path( "cave_data", cavefilename )
if not (settings.CAVEDESCRIPTIONS / cavefilename).is_file: # settings.EXPOWEB / cave_data
cave_data = "does not exist"
+ mvscript += f"mv {cavefilename} {cave.areacode}-{str(knum)}.html\n"
ent_dir = settings.ENTRANCEDESCRIPTIONS # settings.EXPOWEB / "entrance_data"
-
+ mvscript += f"cd {settings.ENTRANCEDESCRIPTIONS }\n"
entrance_data = []
for ent in ent_dir.iterdir():
if str(ent.name).startswith(str(cave)):
print(ent.name)
entrance_data.append("entrance_data/"+ent.name)
+ mvscript += f"mv {ent.name} {ent.name.replace(str(cave),str(knum))}\n"
loser_name = f"caves-{str(cave.areacode)}/{str(cave.unofficial_number)}"
loser_dir = settings.SURVEX_DATA / loser_name
@@ -52,8 +56,10 @@ def kataster(request, slug):
print(loser_dir)
for svx in loser_dir.iterdir():
print(svx)
- loser_data.append(Path(loser_dir , svx).name)
+ loser_data.append(Path(loser_dir , svx).name)
+ return mvscript
+ knum = 9999
if cave := get_cave_from_slug(slug.lower()):
@@ -63,14 +69,18 @@ def kataster(request, slug):
else:
return HttpResponseRedirect("/caves")
- knum = 9999
- do_file_finding()
+ entrances = []
+ for e in cave.entrances(): # horrid CaveAndEntrance indirection we need to refactor out in due course
+ if e.entrance.best_station():
+ entrances.append(e.entrance)
+ _ = do_file_finding(knum)
try:
# this is a python generator idiom.
# see https://realpython.com/introduction-to-python-generators/
# THIS IS VERY SILLY. We have this in the databse fom when this file was parsed. Don't read it again !
+ # However we will need to parse the href= and src= strings in the cave description text, notes etc.
with open(settings.CAVEDESCRIPTIONS / cavefilename, 'r') as f:
for line in f:
if match := re.search(r'
Without fully parsing the entire survex *include tree (which this code does not do), it is impossible to find the *fix declaration file from the 'station' fields in the entrance_data files. However in area 1623 we conventionally store the *fix in a "known" place. This does not work for area 1626. +
Edit these Entrance files: This will cause lost of errors until the cave "{{cave.areacode |safe}}-{{knum}}" has been created by a full database reset.
+ This will cause lots of errors until the cave "{{cave.areacode |safe}}-{{knum}}" has been created by a full database reset OR we can do an online rename of the "Cave" object in the database [code yet to be written] by pressing this button [button not yet implemented].
@@ -105,7 +110,8 @@ git pull
Ideally you do this renumbering on a standalone instance of troggle running on a ⚒ troggle development laptop and you don't push any of the git commits to the server until you have got all the niggles out of the conversion, i.e. the databaseReset runs locally without any warnings or errors introduced by your renaming and 'cavern' runs without any new survex errors.
+
+
{% endblock %}
+{% for e in entrances %}
+
+{{e}}.html
{% if e.tag_station%}tag_station: {{e.tag_station}}{% endif %}
+{% if e.other_station%}other_station: {{e.other_station}}{% endif %}
+{% endfor %}
Set the historic alias forwarder in expoweb
-
("{{cave.slug|safe}}", "{{cave.areacode |safe}}-{{knum}}"), to the end
of the file cave_data/cavealiases.txt (don't forget the comma at the end of the line)
git push
-uv run databaseReset reset K{{knum}}
+uv run databaseReset reset K{{knum}}
+OR we can do an online rename of the "Cave" object in the database [code yet to be written] by pressing the button above [button not yet implemented].
(in fact, look at this before you do any of this, so you can see what chnages.)
@@ -114,4 +120,8 @@ git push
Ideal scenario