2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Therion files now handled

This commit is contained in:
Philip Sargent 2021-04-08 01:09:06 +01:00
parent b7d54111ba
commit cb5b80353d
3 changed files with 23 additions and 9 deletions

View File

@ -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

View File

@ -217,6 +217,8 @@ rx_pcpath = re.compile(rb'<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfsty
def settunnelfileinfo(tunnelfile):
'''Read in the drawing file contents and sets values on the tunnelfile object
Should try to read the date too e.g. tunneldate="2010-08-16 22:51:57
then we could display on the master calendar per expo.
'''
ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE]

12
urls.py
View File

@ -143,12 +143,12 @@ trogglepatterns = [
surveys.surveyscansingle, name="surveyscansingle"),
# The tunnel and therion drawings files pages
url(r'^tunneldata/$', surveys.tunneldata, name="tunneldata"),
url(r'^tunneldataraw/(?P<path>.+?\.xml)$', surveys.tunnelfilesingle, name="tunnelfile"),
url(r'^tunneldataraw/(?P<path>.+?\.th)$', surveys.tunnelfilesingle, name="tunnelfile"),
url(r'^tunneldataraw/(?P<path>.+?\.th2)$', surveys.tunnelfilesingle, name="tunnelfile"),
# url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"), # parses tunnel for info
url(r'^tunneldataraw/(?P<path>.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"),
url(r'^tunneldata/$', surveys.tunneldata, name="tunneldata"),
url(r'^tunneldataraw/(?P<path>.+?\.xml)$', surveys.dwgfilesingle, name="dwgfilesingle"),
url(r'^tunneldataraw/(?P<path>.+?\.th)$', surveys.dwgfilesingle, name="dwgfilesingle"),
url(r'^tunneldataraw/(?P<path>.+?\.th2)$', surveys.dwgfilesingle, name="dwgfilesingle"),
# url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', surveys.tunnelfileinfo, name="tunnelfileinfo"), # parses tunnel for info
url(r'^tunneldataraw/(?P<path>.+?\.xml)/upload$', surveys.tunnelfileupload, name="tunnelfileupload"),
# This next set are all intercepted by Apache, if it is running.
url(r'^photos/(?P<subpath>.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries