mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
look in filesystem not database for file location
This commit is contained in:
parent
a0a1927437
commit
e35616a611
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user