Drawings uploads git works

This commit is contained in:
Philip Sargent
2022-03-05 22:16:03 +00:00
parent a3a65524b8
commit 7a58aac08e
4 changed files with 54 additions and 21 deletions

View File

@@ -32,25 +32,30 @@ 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
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
'''
try:
dwgfile = DrawingFile.objects.get(dwgpath=urlunquote(path))
except:
message = f'Drawing file error or not found \'{path}\' .'
return render(request, 'errors/generic.html', {'message': message})
tfile = Path(settings.DRAWINGS_DATA, dwgfile.dwgpath)
try: # for display not download
return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml")
except UnicodeDecodeError:
try:
return HttpResponse(content=open(tfile,encoding='iso-8859-1'), content_type="text/xhtml")
except:
return HttpResponse(content=open(tfile,mode='rb'), content_type="text/xhtml")
if Path(dwgfile.dwgpath).suffix in ['.xml', 'th2', '.th']:
try: # for display not download
return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml")
except UnicodeDecodeError:
try:
return HttpResponse(content=open(tfile,encoding='iso-8859-1'), content_type="text/xhtml")
except:
return HttpResponse(content=open(tfile,mode='rb'), content_type="text/xhtml")
else:
return HttpResponse(content=open(tfile, errors='ignore'), content_type="text/xhtml")
else:
return HttpResponse(content=open(tfile, errors='ignore'), content_type="text/xhtml")
return HttpResponse(content="Unable to understand the encoding for this file: not UTF-8 nor iso-8859-1, or some other read error happened.")
else:
return HttpResponse(content="Unable to understand the encoding for this file: not UTF-8 nor iso-8859-1, or some other read error happened.")
return HttpResponse(content=open(tfile,"rb"), content_type=getmimetype(tfile))