diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-11-07 18:37:52 +0200 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-11-07 18:37:52 +0200 |
commit | 3f94955883bae222cb049ef5af0b52c31a3ecac4 (patch) | |
tree | 9f278a846409defaefeed8045082c30cf94df1e4 /core/views/caves.py | |
parent | 5652b9b66a8889bad24844ac5dd26cc258cd6a5a (diff) | |
download | troggle-3f94955883bae222cb049ef5af0b52c31a3ecac4.tar.gz troggle-3f94955883bae222cb049ef5af0b52c31a3ecac4.tar.bz2 troggle-3f94955883bae222cb049ef5af0b52c31a3ecac4.zip |
Fix .3d filename
Diffstat (limited to 'core/views/caves.py')
-rw-r--r-- | core/views/caves.py | 33 |
1 files changed, 14 insertions, 19 deletions
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'<h1>Path provided does not correspond to any actual 3d file.</h1><p>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}) |