2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

Fix .3d filename

This commit is contained in:
Philip Sargent 2023-11-07 18:37:52 +02:00
parent 5652b9b66a
commit 3f94955883
2 changed files with 20 additions and 24 deletions

View File

@ -203,8 +203,10 @@ def file3d(request, cave, cave_id):
- If the expected .3d file corresponding to cave.survex_file is present, return it. - If the expected .3d file corresponding to cave.survex_file is present, return it.
- If the cave.survex_file exists, generate the 3d file, cache it and return it - If the cave.survex_file exists, generate the 3d file, cache it and return it
- Use the cave_id to guess what the 3d file might be and, if in the cache, return it - Use the cave_id to guess what the 3d file might be and, if in the cache, return it
- Use the cave_id to guess what the .svx file might be and generate the .3d file and return it
- (Use the incomplete cave.survex_file and a guess at the missing directories to guess the real .svx file location ?) There is a problem as the filename is shown of all areacode information, so both 1624-161 and 1623-161
have a file called 161.svx and return a file called "161.3d" which may
get incorrectly cached by other software (i.e your browser)
""" """
def runcavern(survexpath): def runcavern(survexpath):
@ -212,9 +214,7 @@ def file3d(request, cave, cave_id):
as done in runcavern3d() in parsers/survex.py as done in runcavern3d() in parsers/survex.py
Needs testing. Needs testing.
""" """
# print(" - Regenerating cavern .log and .3d for '{}'".format(survexpath))
if not survexpath.is_file(): if not survexpath.is_file():
# print(" - - Regeneration ABORT\n - - from '{}'".format(survexpath))
pass pass
try: try:
completed_process = subprocess.run( completed_process = subprocess.run(
@ -232,37 +232,33 @@ def file3d(request, cave, cave_id):
print(" - - Regeneration stdout: ", completed_process.stdout) print(" - - Regeneration stdout: ", completed_process.stdout)
print(" - - Regeneration cavern log output: ", op3dlog.read_text()) print(" - - Regeneration cavern log output: ", op3dlog.read_text())
def return3d(threedpath): def return3d(threedpath, cave):
newfilename = cave.slug() + ".3d" # add the "1623-" part of the filename effectively.
if threedpath.is_file(): if threedpath.is_file():
response = HttpResponse(content=open(threedpath, "rb"), content_type="application/3d") response = HttpResponse(content=open(threedpath, "rb"), content_type="application/3d")
response["Content-Disposition"] = f"attachment; filename={threedpath.name}" response["Content-Disposition"] = f"attachment; filename={newfilename}"
return response return response
else: else:
message = f'<h1>Path provided does not correspond to any actual 3d file.</h1><p>path: "{threedpath}"' message = f'<h1>Path provided does not correspond to any actual 3d file.</h1><p>path: "{threedpath}"'
# print(message)
return HttpResponseNotFound(message) return HttpResponseNotFound(message)
survexname = Path(cave.survex_file).name # removes directories survexname = Path(cave.survex_file).name # removes directories ie 1623/161/161.svx -> 161.svx
survexpath = Path(settings.SURVEX_DATA, cave.survex_file) survexpath = Path(settings.SURVEX_DATA, cave.survex_file)
threedname = Path(survexname).with_suffix(".3d") # removes .svx, replaces with .3d survexdir = survexpath.parent
threedpath = Path(settings.SURVEX_DATA, threedname) threedname = Path(survexname).with_suffix(".3d") # removes .svx, replaces with .3d AND DISCARDS PATH arrgh
threedpath = survexpath.parent / threedname
# These if statements need refactoring more cleanly # These if statements need refactoring more cleanly
if cave.survex_file: if cave.survex_file:
# print(" - cave.survex_file '{}'".format(cave.survex_file))
if threedpath.is_file(): if threedpath.is_file():
# print(" - threedpath '{}'".format(threedpath))
# possible error here as several .svx files of same names in different directories will overwrite in /3d/
if survexpath.is_file(): if survexpath.is_file():
if os.path.getmtime(survexpath) > os.path.getmtime(threedpath): if os.path.getmtime(survexpath) > os.path.getmtime(threedpath):
runcavern(survexpath) runcavern(survexpath)
return return3d(threedpath) return return3d(threedpath, cave)
else: else:
# print(" - - survexpath '{}'".format(survexpath))
if survexpath.is_file(): if survexpath.is_file():
# print(" - - - survexpath '{}'".format(survexpath))
runcavern(survexpath) runcavern(survexpath)
return return3d(threedpath) return return3d(threedpath, cave)
# Get here if cave.survex_file was set but did not correspond to a valid svx file # Get here if cave.survex_file was set but did not correspond to a valid svx file
if survexpath.is_file(): if survexpath.is_file():
@ -279,7 +275,6 @@ def rendercave(request, cave, slug, cave_id=""):
"""Gets the data and files ready and then triggers Django to render the template. """Gets the data and files ready and then triggers Django to render the template.
The resulting html contains urls which are dispatched independently, e.g. the 'download' link The resulting html contains urls which are dispatched independently, e.g. the 'download' link
""" """
# print(" ! rendercave:'{}' START slug:'{}' cave_id:'{}'".format(cave, slug, cave_id))
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
return render(request, "nonpublic.html", {"instance": cave, "cavepage": True, "cave_id": cave_id}) return render(request, "nonpublic.html", {"instance": cave, "cavepage": True, "cave_id": cave_id})

View File

@ -5,7 +5,7 @@
<!-- <!--
# We put every .3d file in the same folder as # We put every .3d file in the same folder as
# the .svx file, using the {{svx3d}} template variable set in rendercave() in # the .svx file, using the {{svx3d}} template variable set in rendercave() in
# core/views/caves.py but with a full path. THIS IS NOW DONE March 2022. # core/views/caves.py .
#--> #-->
<link type="text/css" href="/javascript/CaveView/css/caveview.css" rel="stylesheet"/> <link type="text/css" href="/javascript/CaveView/css/caveview.css" rel="stylesheet"/>
<script type="text/javascript" src="/javascript/CaveView/js/CaveView2.js" ></script> <script type="text/javascript" src="/javascript/CaveView/js/CaveView2.js" ></script>
@ -18,7 +18,7 @@
const viewer = new CV2.CaveViewer( 'scene', { const viewer = new CV2.CaveViewer( 'scene', {
home: '/javascript/CaveView/', home: '/javascript/CaveView/',
//Wookey old code surveyDirectory: '/expowebcache/3d/', //Wookey old code surveyDirectory: '/expowebcache/3d/',
surveyDirectory: '/cave/3d/', surveyDirectory: '/cave/3d/', // this is a fake Django url which should return the right place
terrainDirectory: '/loser/surface/terrain/' // cannot work, apache not handling this url terrainDirectory: '/loser/surface/terrain/' // cannot work, apache not handling this url
} ); } );
@ -27,7 +27,8 @@
const ui = new CV2.CaveViewUI( viewer ); const ui = new CV2.CaveViewUI( viewer );
//Wookey old code: ui.loadCave('{{svx3d}}.3d'); //Wookey old code: ui.loadCave('{{svx3d}}.3d');
ui.loadCave('{{ cave }}.3d'); //Wookey new code
ui.loadCave('{{ cave }}.3d'); // ie '1624-161.3d' Troggle used to return a file 161.3d but now returns 1623-161.3d
document.getElementById('scene').style.cssText = "background-color: rgb(0, 0, 0); position: relative !important;" document.getElementById('scene').style.cssText = "background-color: rgb(0, 0, 0); position: relative !important;"
} }
@ -42,7 +43,7 @@
{% block contentheader %} {% block contentheader %}
<table id="cavepage"> <table id="cavepage">
<tr> <tr>
<th id="kat_no"><!-- why is this not showing unofficial_number??--> <th id="kat_no">
{{ cave.areacode}} / {{ cave.areacode}} /
{% if cave.kataster_number %} {% if cave.kataster_number %}
{{ cave.kataster_number|safe }} {{ cave.kataster_number|safe }}
@ -205,7 +206,7 @@
{% if cave.survex_file %} {% if cave.survex_file %}
Primary <a href="/survexfile/{{cave.survex_file}}">survex file</a> for this cave Primary <a href="/survexfile/{{cave.survex_file}}">survex file</a> for this cave
<br> <br>
Download .3d file <a href="{% url "cave3d" cave %}">{% url "cave3d" cave %}</a> Download .3d file <a href="{% url "cave3d" cave %}">{{cave}}.3d</a><!-- this is a fake directory -->
<br> <br>
cave survex path '{{ cave.areacode }}/{% if cave.kataster_number %}{{cave.kataster_number}}{% else %}{{cave.unofficial_number}}{% endif %}/' cave survex path '{{ cave.areacode }}/{% if cave.kataster_number %}{{cave.kataster_number}}{% else %}{{cave.unofficial_number}}{% endif %}/'
<div id='scene'></div> <div id='scene'></div>