summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-01-31 18:30:22 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-01-31 18:30:22 +0000
commit43634fb47547a5fbfbc2af1ead93f8597f4925a3 (patch)
tree9e71713ee9c793fd2b59e4bda0d6416ca04658c7
parent49ea30cf0691bfb075791d6a6f9837db9392ff88 (diff)
downloadtroggle-43634fb47547a5fbfbc2af1ead93f8597f4925a3.tar.gz
troggle-43634fb47547a5fbfbc2af1ead93f8597f4925a3.tar.bz2
troggle-43634fb47547a5fbfbc2af1ead93f8597f4925a3.zip
initial rename script textarea
-rw-r--r--core/views/cave_kataster.py33
-rw-r--r--templates/cave_kataster.html18
2 files changed, 39 insertions, 12 deletions
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'<entranceslug>(.*?)</entranceslug>', line):
@@ -85,24 +95,31 @@ def kataster(request, slug):
msg=f"CANNOT write this file {filepath}. Ask a nerd to fix this: {e}"
print(msg)
+ script = ""
+
if request.method == "POST": # If the form has been submitted...
form = KatasterForm(request.POST) # A form bound to the POST data
if form.is_valid():
clean = form.cleaned_data
knum = clean['kataster_number']
print(f" # kataster_number {clean['kataster_number']}")
+
+ # DETECT if this is an LAREADY USED kataster number in this area ! If so, WARNING!!
+ # (we might be half-way through, so it might exist)
else: # GET and fall-through if POST is not valid
form = KatasterForm()
+ script += do_file_finding(knum)
+
return render(
request,
"cave_kataster.html",
{
"form": form,
- "cave": cave,
+ "cave": cave, "entrances": entrances,
"cave_data": cave_data, "entrance_data": entrance_data,
"loser_name": loser_name, "loser_data": loser_data,
- "knum": knum,
+ "knum": knum, "script": script,
}, )
class KatasterForm(forms.Form):
diff --git a/templates/cave_kataster.html b/templates/cave_kataster.html
index eaee28c..771f89e 100644
--- a/templates/cave_kataster.html
+++ b/templates/cave_kataster.html
@@ -75,19 +75,24 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
<h3>Sort out the *fix point(s) in both <var>loser</var> and in <var>expoweb</var></h3>
<ul style="list-style: disc">
-<li> Find the *fix point for each entrance (one or more in each <samp>entrance_data</samp> file) in <var>expoweb</var>. There are three fields where there might be a *fix value: <samp>'tag_station', 'exact_station'</samp> and <samp>'other_station'</samp>
-
+<li> Find the *fix point for each entrance (one or more in each <samp>entrance_data</samp> file) in <var>expoweb</var>. There are two fields on an Entrance where there might be a location: <samp>'tag_station', or <samp>'other_station'</samp>. These refer to a survex survey point, which might be *fix elsewhere or one of the survey points in one of the cave survex files.
<li> Change the name of each *fix point in the relevant survex file in <var>loser</var>
<li> Make the same name change(s) in each entrance file (in each <samp>entrance_data</samp> file) in <var>expoweb</var>
</ul>
<p>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 <samp>'station'</samp> 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.
+<p>Edit these Entrance files:<br />
+{% for e in entrances %}
+<samp>
+{{e}}.html<br />&nbsp;&nbsp;&nbsp;{% if e.tag_station%}</samp>tag_station: <samp>{{e.tag_station}}{% endif %}
+{% if e.other_station%}</samp>other_station: <samp>{{e.other_station}}{% endif %}<br /><samp>
+{% endfor %}
<h3>Set the historic alias forwarder in <var>expoweb</var></h3>
<ul style="list-style: disc">
<li> Add the line <br /><samp>("{{cave.slug|safe}}", "<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"),</samp></br /> to the end
of the file <var><a href="/cave_data/cavealiases.txt_edit">cave_data/cavealiases.txt</a></var> (don't forget the comma at the end of the line)
</ul>
-<p>This will cause lost of errors until the cave <samp>"<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"</samp> has been created by a full database reset.
+<p>This will cause lots of errors until the cave <samp>"<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"</samp> 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].
<!--or by editing & saving the cave description page <a href="/{{cave.areacode |safe}}/{{knum}}">/{{cave.areacode |safe}}/{{knum}}</a> after renaming. (Editing a cave description page regenerates some of the internal indices.)
-->
@@ -105,7 +110,8 @@ git pull<br />
git push<br />
</samp>
<li>It is then vital to do a complete databaseReset as troggle has internally indexed all those {{cave.slug}} files, the indexes are now out of date and horrible things will happen when people try to use troggle with any cave that has been altered:<br />
-<samp>uv run databaseReset reset <span style="color:blue">K{{knum}}</span></samp>
+<samp>uv run databaseReset reset <span style="color:blue">K{{knum}}</span></samp><br />
+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].
<li>Look in the reset import warnings and errors report to see if anything has gone wrong:
<var><a href="http://expo.survex.com/dataissues">expo.survex.com/dataissues</a></var><br />
(in fact, look at this before you do any of this, so you can see what chnages.)
@@ -114,4 +120,8 @@ git push<br />
<h3>Ideal scenario</h3>
<p>
<p>Ideally you do this renumbering on a standalone instance of troggle running on a <var> &#9874; <a href="/handbook/troggle/troglaptop.html">troggle development laptop</a></var> 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 <em>and</em> 'cavern' runs without any new survex errors.
+<p>
+<textarea id="script" name="script" rows="15" cols="100" style="font-size:small">
+{{script}}
+</textarea>
{% endblock %}