diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/views/surveys.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/core/views/surveys.py b/core/views/surveys.py index 63eaf2b..7cf0d83 100644 --- a/core/views/surveys.py +++ b/core/views/surveys.py @@ -44,12 +44,24 @@ def tunneldata(request): return render(request, 'tunnelfiles.html', { 'tunnelfiles':tunnelfiles, 'settings': settings }) -def tunnelfilesingle(request, path): +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 ''' - tunnelfile = TunnelFile.objects.get(tunnelpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error + tunnelfile = TunnelFile.objects.get(tunnelpath=urlunquote(path)) # need to check if invalid query string and produce friendly error tfile = Path(settings.TUNNEL_DATA, tunnelfile.tunnelpath) - return HttpResponse(content=open(tfile), content_type="text/xhtml") # for display not download + 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="Unable to understand the encoding for this file: not UTF-8 nor iso-8859-1, or some other read error happened.") + def tunnelfileupload(request, path): tunnelfile = TunnelFile.objects.get(tunnelpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error |