From cb5b80353daec09cf6db290d182f51be1befe77d Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 8 Apr 2021 01:09:06 +0100 Subject: [PATCH] Therion files now handled --- core/views/surveys.py | 18 +++++++++++++++--- parsers/surveys.py | 2 ++ urls.py | 12 ++++++------ 3 files changed, 23 insertions(+), 9 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 diff --git a/parsers/surveys.py b/parsers/surveys.py index dbbc537..40a12f0 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -217,6 +217,8 @@ rx_pcpath = re.compile(rb'.+?\.xml)$', surveys.tunnelfilesingle, name="tunnelfile"), - url(r'^tunneldataraw/(?P.+?\.th)$', surveys.tunnelfilesingle, name="tunnelfile"), - url(r'^tunneldataraw/(?P.+?\.th2)$', surveys.tunnelfilesingle, name="tunnelfile"), -# url(r'^tunneldatainfo/(?P.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"), # parses tunnel for info - url(r'^tunneldataraw/(?P.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"), + url(r'^tunneldata/$', surveys.tunneldata, name="tunneldata"), + url(r'^tunneldataraw/(?P.+?\.xml)$', surveys.dwgfilesingle, name="dwgfilesingle"), + url(r'^tunneldataraw/(?P.+?\.th)$', surveys.dwgfilesingle, name="dwgfilesingle"), + url(r'^tunneldataraw/(?P.+?\.th2)$', surveys.dwgfilesingle, name="dwgfilesingle"), +# url(r'^tunneldatainfo/(?P.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"), # parses tunnel for info + url(r'^tunneldataraw/(?P.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"), # This next set are all intercepted by Apache, if it is running. url(r'^photos/(?P.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries