summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-04-08 01:09:06 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-04-08 01:09:06 +0100
commitcb5b80353daec09cf6db290d182f51be1befe77d (patch)
treea5b493e6dee4643e11f8758eaafa04bafdfe4e3a /core
parentb7d54111ba1b698ed57eb7b3a69896c7f6146cb5 (diff)
downloadtroggle-cb5b80353daec09cf6db290d182f51be1befe77d.tar.gz
troggle-cb5b80353daec09cf6db290d182f51be1befe77d.tar.bz2
troggle-cb5b80353daec09cf6db290d182f51be1befe77d.zip
Therion files now handled
Diffstat (limited to 'core')
-rw-r--r--core/views/surveys.py18
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