diff options
-rw-r--r-- | core/views/cave_kataster.py | 33 | ||||
-rw-r--r-- | templates/cave_kataster.html | 15 |
2 files changed, 38 insertions, 10 deletions
diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py index 96bfe6a..747e88a 100644 --- a/core/views/cave_kataster.py +++ b/core/views/cave_kataster.py @@ -34,14 +34,15 @@ def kataster(request, slug): mvscript = f"cd {settings.CAVEDESCRIPTIONS }\n"
cavefilename = str(cave) + ".html"
+ target= f"{cave.areacode}-{str(knum)}"
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"
+ mvscript += f"mv {cavefilename} {target}.html\n"
ent_dir = settings.ENTRANCEDESCRIPTIONS # settings.EXPOWEB / "entrance_data"
- mvscript += f"cd {settings.ENTRANCEDESCRIPTIONS }\n"
+ mvscript += f"\ncd {settings.ENTRANCEDESCRIPTIONS }\n"
entrance_data = []
for ent in ent_dir.iterdir():
if str(ent.name).startswith(str(cave)):
@@ -58,7 +59,21 @@ def kataster(request, slug): print(svx)
loser_data.append(Path(loser_dir , svx).name)
return mvscript
-
+
+ def script_loser(knum):
+ global cavefilename, cave_data, entrance_data, loser_name, loser_data
+
+ target= f"caves-{cave.areacode}/{str(knum)}"
+ l_script = f"\ncd {settings.SURVEX_DATA}\n"
+ l_script +=f"mv {loser_name} {target}\n"
+ l_script +=f"cd {target}\n# But note that git ignores .log and .3d files\n"
+ for filename in loser_data:
+ l_script +=f"mv {filename} {filename.replace(str(cave.unofficial_number),str(knum))}\n"
+
+ return l_script
+
+
+
knum = 9999
@@ -95,8 +110,11 @@ def kataster(request, slug): msg=f"CANNOT write this file {filepath}. Ask a nerd to fix this: {e}"
print(msg)
- script = ""
-
+ # Restart script with POST data
+ script = "# Conversion script\n# When doing it by hand, it is less error-prone to do the file re-namings last,\n"
+ script += "# but in a script it does not matter so much, so long as everything is consistent and tested,\n"
+ script += "# except that reversing changes using git does not always restore directories exactly.\n\n"
+ script += "# Be careful with the directory names, they might not be the same on your PC as on the server\n\n"
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():
@@ -110,6 +128,9 @@ def kataster(request, slug): form = KatasterForm()
script += do_file_finding(knum)
+ script += script_loser(knum)
+ script_rows = str(min(35,3+script.count('\n')))
+
return render(
request,
@@ -119,7 +140,7 @@ def kataster(request, slug): "cave": cave, "entrances": entrances,
"cave_data": cave_data, "entrance_data": entrance_data,
"loser_name": loser_name, "loser_data": loser_data,
- "knum": knum, "script": script,
+ "knum": knum, "script": script, "rows": script_rows,
}, )
class KatasterForm(forms.Form):
diff --git a/templates/cave_kataster.html b/templates/cave_kataster.html index 771f89e..d8d57ae 100644 --- a/templates/cave_kataster.html +++ b/templates/cave_kataster.html @@ -11,20 +11,20 @@ <h3>Cave <a href="/{{cave.url|safe}}">{{cave.slug|safe}}</a> '{{cave.official_name|safe}}'</h3> - + <form action="{% url 'kataster' cave.slug %}" method="post"> <p> {% if cave.kataster_number %} <b>This cave has already been "katastered". area:{{cave.areacode |safe}} number:{{cave.kataster_number |safe}} </b> {% else %} This cave needs to be "katastered". If you have the new number issued by the Austrians, we can do it now. - <form action="{% url 'kataster' cave.slug %}" method="post"> + {% csrf_token %} {{form.as_p}} <button class="fancybutton" style="padding: 0.5em 25px; font-size: 100%;" type = "submit" > See what the edits look like → </button> -</form> + {% endif %} <h3>Rename the .html files in <var>expoweb</var></h3> @@ -121,7 +121,14 @@ OR we can do an online rename of the "Cave" object in the database [code yet to <p> <p>Ideally you do this renumbering on a standalone instance of troggle running on a <var> ⚒ <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"> + +<textarea id="script" name="script" rows="{{rows}}" cols="100" style="font-size:small; font-weight: bold; background-color: LemonChiffon"> {{script}} </textarea> +<br /> +<!-- duplicate button at bottom of long page --> + <button class="fancybutton" style="padding: 0.5em 25px; font-size: 100%;" type = "submit" > + See what the edits look like → + </button> +</form> {% endblock %} |