From e35616a6114de58536c7c01aa328905044c83f7b Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 11 Aug 2022 22:18:58 +0300 Subject: [PATCH] look in filesystem not database for file location --- core/views/drawings.py | 22 +++++++++++++--------- 1 file 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: