diff --git a/core/views/caves.py b/core/views/caves.py index 9d2512d..5ac3725 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -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 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 .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): @@ -212,9 +214,7 @@ def file3d(request, cave, cave_id): 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( @@ -232,37 +232,33 @@ def file3d(request, cave, cave_id): print(" - - Regeneration stdout: ", completed_process.stdout) 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(): 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 else: message = f'

Path provided does not correspond to any actual 3d file.

path: "{threedpath}"' - # print(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) - threedname = Path(survexname).with_suffix(".3d") # removes .svx, replaces with .3d - threedpath = Path(settings.SURVEX_DATA, threedname) - + survexdir = survexpath.parent + 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 if cave.survex_file: - # print(" - cave.survex_file '{}'".format(cave.survex_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 os.path.getmtime(survexpath) > os.path.getmtime(threedpath): runcavern(survexpath) - return return3d(threedpath) + return return3d(threedpath, cave) else: - # print(" - - survexpath '{}'".format(survexpath)) if survexpath.is_file(): - # print(" - - - survexpath '{}'".format(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 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. 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: return render(request, "nonpublic.html", {"instance": cave, "cavepage": True, "cave_id": cave_id}) diff --git a/templates/cave.html b/templates/cave.html index 3e94747..a04bb93 100644 --- a/templates/cave.html +++ b/templates/cave.html @@ -5,7 +5,7 @@ @@ -18,7 +18,7 @@ const viewer = new CV2.CaveViewer( 'scene', { home: '/javascript/CaveView/', //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 } ); @@ -27,7 +27,8 @@ const ui = new CV2.CaveViewUI( viewer ); //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;" } @@ -42,7 +43,7 @@ {% block contentheader %} -
+ {{ cave.areacode}} / {% if cave.kataster_number %} {{ cave.kataster_number|safe }} @@ -205,7 +206,7 @@ {% if cave.survex_file %} Primary survex file for this cave
- Download .3d file {% url "cave3d" cave %} + Download .3d file {{cave}}.3d
cave survex path '{{ cave.areacode }}/{% if cave.kataster_number %}{{cave.kataster_number}}{% else %}{{cave.unofficial_number}}{% endif %}/'