From dd0a448f904347f007b23f58d0d78eed9d2987fd Mon Sep 17 00:00:00 2001
From: Philip Sargent <philip.sargent@klebos.com>
Date: Thu, 21 Jul 2022 01:22:07 +0300
Subject: [PATCH] fix 3d file download on cave page

---
 core/views/caves.py | 12 ++++++++----
 templates/cave.html |  5 ++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/core/views/caves.py b/core/views/caves.py
index 145aeb2..44dbb80 100644
--- a/core/views/caves.py
+++ b/core/views/caves.py
@@ -145,17 +145,21 @@ def file3d(request, cave, cave_id):
     - (Use the incomplete cave.survex_file and a guess at the missing directories to guess the real .svx file location ?)   
     '''
     def runcavern(survexpath):
+        '''This has not yet been properly updated with respect to putting the .3d file in the same folder as the .svx filse
+        as done in runcavern3d() in parsers/survex.py 
+        Needs testing.
+        '''
         #print(" -  Regenerating cavern .log and .3d for '{}'".format(survexpath))
         if not survexpath.is_file():
             #print(" -  - Regeneration ABORT\n -  - from '{}'".format(survexpath))
             pass
         try:
-            completed_process = subprocess.run([settings.CAVERN, "--log", "--output={}".format(settings.THREEDCACHEDIR), "{}".format(survexpath)])
+            completed_process = subprocess.run([settings.CAVERN, "--log", "--output={}".format(settings.SURVEX_DATA), "{}".format(survexpath)])
         except OSError as ex:
             # propagate this to caller. 
             raise OSError(completed_process.stdout) from ex
 
-        op3d = (Path(settings.THREEDCACHEDIR) / Path(survexpath).name).with_suffix('.3d')
+        op3d = (Path(settings.SURVEX_DATA) / Path(survexpath).name).with_suffix('.3d')
         op3dlog = Path(op3d.with_suffix('.log'))
 
         if not op3d.is_file():
@@ -177,8 +181,8 @@ def file3d(request, cave, cave_id):
     survexname = Path(cave.survex_file).name # removes directories
     survexpath = Path(settings.SURVEX_DATA, cave.survex_file)
     threedname = Path(survexname).with_suffix('.3d') # removes .svx, replaces with .3d
-    threedpath = Path(settings.THREEDCACHEDIR, threedname) 
-    threedcachedir = Path(settings.THREEDCACHEDIR)
+    threedpath = Path(settings.SURVEX_DATA, threedname) 
+    threedcachedir = Path(settings.SURVEX_DATA)
     
     # These if statements need refactoring more cleanly
     if cave.survex_file:
diff --git a/templates/cave.html b/templates/cave.html
index ce6bb3d..fab7343 100644
--- a/templates/cave.html
+++ b/templates/cave.html
@@ -518,9 +518,8 @@ div#scene {
 {% if cave.survex_file %}
     <h2>Survex File</h2>
     <p><a href="https://aardgoose.github.io/CaveView.js/">CaveView</a> display of the .3d file is temporarily disabled while we fix things (Nov.2021). See <a href="/handbook/computing/todo.html">/handbook/computing/todo.html</a>.<br>
-    <a href="/survexfile">All survex files</a> &nbsp;&nbsp;&nbsp;<br>
-    <a href="{% if cave.kataster_number %}{% url "cave3d" cave.kataster_number %}{% else %}{% url "cave3d" cave.unofficial_number %}{% endif %}">3d file download</a>&nbsp;&nbsp;&nbsp;<br>
-    <a href="{% if cave.kataster_number %}{% url "survexcavessingle" cave.kataster_number %}">This survex file</a> &nbsp;&nbsp;&nbsp;{% endif %}
+    <a href="{% if cave.kataster_number %}{% url "cave3d" cave.kataster_number %}           {% else %}{% url "cave3d" cave.unofficial_number %}           {% endif %}">3d file download</a>&nbsp;for this cave<br>
+    <a href="{% if cave.kataster_number %}{% url "survexcavessingle" cave.kataster_number %}{% else %}{% url "survexcavessingle" cave.unofficial_number %}{% endif %}">survex file</a> &nbsp;for this cave
     
     <div id='scene'></div>
 {% endif %}