summaryrefslogtreecommitdiffstats
path: root/core/views/drawings.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2022-08-11 22:18:58 +0300
committerPhilip Sargent <philip.sargent@klebos.com>2022-08-11 22:18:58 +0300
commite35616a6114de58536c7c01aa328905044c83f7b (patch)
treeee1db430c3800c25e72623b8498208ec1a1a6b0a /core/views/drawings.py
parenta0a192743796f5aacd8e48f0767aa397bbe666e7 (diff)
downloadtroggle-e35616a6114de58536c7c01aa328905044c83f7b.tar.gz
troggle-e35616a6114de58536c7c01aa328905044c83f7b.tar.bz2
troggle-e35616a6114de58536c7c01aa328905044c83f7b.zip
look in filesystem not database for file location
Diffstat (limited to 'core/views/drawings.py')
-rw-r--r--core/views/drawings.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/core/views/drawings.py b/core/views/drawings.py
index d6a1599..5e60130 100644
--- a/core/views/drawings.py
+++ b/core/views/drawings.py
@@ -18,7 +18,7 @@ by looking inside the file before being served.
'''
-todo='''Need to check if invalid query string is invalid, or produces multiple replies
+todo='''- Need to check if invalid query string is invalid, or produces multiple replies
and render a user-friendly error page.
'''
@@ -33,17 +33,21 @@ def dwgallfiles(request):
def dwgfilesingle(request, path):
'''sends a single binary file to the user, We should have a renderer that syntax-colours this Tunnel xml
but it might be a Therion file. And it could be an old PNG, PDF or SVG for that matter,
- so we should attempt to render it
+ so we should attempt to render it.
+
+ The db records created on datbase reset import are not use when we look for an individual drawing, only
+ collections of them.
+
+ Note the infelicity that this will deliver files that exist, but are hidden on the previous
+ webpage /dwgupload/... if the user types the filename into the browser bar. Could be a problem?
+ Should we validate using uploads.py dwgvaliddisp() here too?
'''
- try:
- dwgfile = DrawingFile.objects.get(dwgpath=urlunquote(path))
- except:
- message = f'Drawing file error or not found \'{path}\' .'
+ tfile = Path(settings.DRAWINGS_DATA, path)
+ if not tfile.is_file():
+ message = f'Drawing file not found in filesystem at \'{path}\' .'
return render(request, 'errors/generic.html', {'message': message})
- tfile = Path(settings.DRAWINGS_DATA, dwgfile.dwgpath)
-
- if Path(dwgfile.dwgpath).suffix in ['.xml', 'th2', '.th']:
+ if Path(tfile).suffix in ['.xml', 'th2', '.th']:
try: # for display not download
return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml")
except UnicodeDecodeError: