From dc840c9bc773fa848e8903d65e657333c3ad2cd2 Mon Sep 17 00:00:00 2001
From: Philip Sargent <philip.sargent@klebos.com>
Date: Mon, 26 Apr 2021 18:11:14 +0100
Subject: [PATCH] tunnelpath to dwgpath

---
 core/models/survex.py   |  4 ++--
 core/views/surveys.py   |  8 ++++----
 parsers/caves.py        |  2 +-
 parsers/surveys.py      | 18 +++++++++---------
 templates/dwgfiles.html |  4 ++--
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/core/models/survex.py b/core/models/survex.py
index 31f4646..7551470 100644
--- a/core/models/survex.py
+++ b/core/models/survex.py
@@ -200,7 +200,7 @@ class SingleScan(models.Model):
         return "Survey Scan Image: " + str(self.name) + " in " + str(self.scansfolder)
 
 class DrawingFile(models.Model):
-    tunnelpath          = models.CharField(max_length=200)
+    dwgpath          = models.CharField(max_length=200)
     tunnelname          = models.CharField(max_length=200)
     bfontcolours        = models.BooleanField(default=False) # UNUSED now, can be deleted
     manyscansfolders    = models.ManyToManyField("ScansFolder") # implicitly links via folders to scans to SVX files
@@ -211,4 +211,4 @@ class DrawingFile(models.Model):
     survexfiles         = models.ManyToManyField("SurvexFile")  # direct link to SVX files - not populated yet
 
     class Meta:
-        ordering = ('tunnelpath',)
\ No newline at end of file
+        ordering = ('dwgpath',)
\ No newline at end of file
diff --git a/core/views/surveys.py b/core/views/surveys.py
index d149d4e..cf18fdd 100644
--- a/core/views/surveys.py
+++ b/core/views/surveys.py
@@ -59,12 +59,12 @@ def dwgfilesingle(request, path):
     but it might be a Therion file
     '''
     try:
-        dwgfile = DrawingFile.objects.get(tunnelpath=urlunquote(path)) 
+        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.TUNNEL_DATA, dwgfile.tunnelpath)
+    tfile = Path(settings.TUNNEL_DATA, dwgfile.dwgpath)
     try: # for display not download
         return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml") 
     except UnicodeDecodeError:
@@ -82,11 +82,11 @@ def dwgfileupload(request, path):
     '''uploads a drawing file, but where is the Form? This just processes POST info. Apparently unfinished?
     '''
     try:
-        dwgfile = DrawingFile.objects.get(tunnelpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error
+        dwgfile = DrawingFile.objects.get(dwgpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error
     except:
         message = f'Drawing file error or not found \'{path}\' .'
         return render(request, 'errors/generic.html', {'message': message})   
-    tfile = Path(settings.TUNNEL_DATA, dwgfile.tunnelpath)
+    tfile = Path(settings.TUNNEL_DATA, dwgfile.dwgpath)
     
     project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], request.POST["tunnelversion"]
     print(project, user, tunnelversion)
diff --git a/parsers/caves.py b/parsers/caves.py
index 3a58748..6b17878 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -61,7 +61,7 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"):
         letter = ""
         entrances_xslug[slug] = entrance
         ce = CaveAndEntrance.objects.update_or_create(cave = cave, entrance_letter = "", entrance = entrance)
-        message = f' ! Entrance Dummy setting WORKED, slug:"{slug}" cave id:"{id}" '
+        message = f' ! Warning: Dummy Entrance created for {id}, slug:"{slug}" '
         DataIssue.objects.create(parser='caves', message=message, url=f'/cave/{slug}')
         print(message)
     except:
diff --git a/parsers/surveys.py b/parsers/surveys.py
index 30361d4..e0ecf27 100644
--- a/parsers/surveys.py
+++ b/parsers/surveys.py
@@ -130,7 +130,7 @@ def find_tunnel_scan(dwgfile, path):
         if len(scansfolderl):
             scansfolder = scansfolderl[0]
             if len(scansfolderl) > 1:
-                message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.tunnelpath, path)
+                message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path)
                 print(message)
                 DataIssue.objects.create(parser='Tunnel', message=message)
             
@@ -138,7 +138,7 @@ def find_tunnel_scan(dwgfile, path):
             scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2))
             if len(scansfilel):
                 if len(scansfilel) > 1:
-                    message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.tunnelpath, path)
+                    message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path)
                     print(message)
                     DataIssue.objects.create(parser='Tunnel', message=message)
                 scansfile = scansfilel[0]
@@ -179,7 +179,7 @@ def settherionfileinfo(filetuple):
     '''
     thtype, therionfile = filetuple
     
-    ff = os.path.join(settings.TUNNEL_DATA, therionfile.tunnelpath)
+    ff = os.path.join(settings.TUNNEL_DATA, therionfile.dwgpath)
     therionfile.filesize = os.stat(ff)[stat.ST_SIZE]
     if therionfile.filesize <= 0:
         message = "! Zero length therion file {}".format(ff)
@@ -206,7 +206,7 @@ def settherionfileinfo(filetuple):
     # scrap blownout -projection plan -scale [-81.0 -42.0 216.0 -42.0 0.0 0.0 7.5438 0.0 m]
     
     for xth_me in rx_xth_me.findall(ttext):
-        message = f'! Un-parsed image filename: {therionfile.tunnelname} : {xth_me.split()[-3]} - {therionfile.tunnelpath}'
+        message = f'! Un-parsed image filename: {therionfile.tunnelname} : {xth_me.split()[-3]} - {therionfile.dwgpath}'
         #print(message)
         DataIssue.objects.create(parser='Therion', message=message)
         findimageinsert(therionfile, xth_me)
@@ -214,7 +214,7 @@ def settherionfileinfo(filetuple):
     for inp in rx_input.findall(ttext):
         # if this 'input' is a .th2 file we have already seen, then we can assign this as a sub-file
         # but we would need to disentangle to get the current path properly
-        message = f'! Un-set Therion .th2 input: - {therionfile.tunnelname} : {inp} - {therionfile.tunnelpath}'
+        message = f'! Un-set Therion .th2 input: - {therionfile.tunnelname} : {inp} - {therionfile.dwgpath}'
         #print(message)
         DataIssue.objects.create(parser='Therion', message=message)
         findimportinsert(therionfile, inp)
@@ -229,7 +229,7 @@ def setdwgfileinfo(dwgfile):
     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, dwgfile.tunnelpath)
+    ff = os.path.join(settings.TUNNEL_DATA, dwgfile.dwgpath)
     dwgfile.filesize = os.stat(ff)[stat.ST_SIZE]
     if dwgfile.filesize <= 0:
         message = "! Zero length xml file {}".format(ff)
@@ -278,17 +278,17 @@ def load_drawings_files():
                 drawingsdirs.append(lf) # lunatic! adding to list in middle of list while loop!
             elif f[-4:] == ".xml":
                 # Always creates new
-                dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+                dwgfile = DrawingFile(dwgpath=lf, tunnelname=os.path.split(f[:-4])[1])
                 dwgfile.save()
                 all_xml.append(('xml',dwgfile))
             elif f[-3:] == ".th":
                 # Always creates new
-                dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+                dwgfile = DrawingFile(dwgpath=lf, tunnelname=os.path.split(f[:-4])[1])
                 dwgfile.save()
                 all_xml.append(('th',dwgfile))
             elif f[-4:] == ".th2":
                 # Always creates new
-                dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+                dwgfile = DrawingFile(dwgpath=lf, tunnelname=os.path.split(f[:-4])[1])
                 dwgfile.save()
                 all_xml.append(('th2',dwgfile))
 
diff --git a/templates/dwgfiles.html b/templates/dwgfiles.html
index 2f71196..ff3a31b 100644
--- a/templates/dwgfiles.html
+++ b/templates/dwgfiles.html
@@ -12,7 +12,7 @@
 
 {% for dwgfile in dwgfiles %}
   <tr>
-    <td><a href="{% url "dwgfilesingle" dwgfile.tunnelpath %}">{{dwgfile.tunnelpath}}</a></td>
+    <td><a href="{% url "dwgfilesingle" dwgfile.dwgpath %}">{{dwgfile.dwgpath}}</a></td>
     <td align="right" style="padding:2px">{{dwgfile.filesize}}</td>
     <td align="right" style="padding:2px">{{dwgfile.npaths}}</td>   
 
@@ -30,7 +30,7 @@
 
     <td style="padding:2px">
     {% for rdwgfile in dwgfile.tunnelcontains.all %}
-      <a href="{% url "dwgfilesingle" rdwgfile.tunnelpath %}">{{rdwgfile.tunnelpath}}</a>
+      <a href="{% url "dwgfilesingle" rdwgfile.dwgpath %}">{{rdwgfile.dwgpath}}</a>
     {% endfor %}
     </td>   
   </tr>