From 1ff723554cf46dc644a0fa2a295ef175bc43b4d5 Mon Sep 17 00:00:00 2001
From: Philip Sargent <philip.sargent@klebos.com>
Date: Fri, 7 May 2021 22:42:10 +0100
Subject: [PATCH] Northings and Easting report

---
 core/views/statistics.py | 13 ++++++++++++-
 settings.py              |  6 +++---
 templates/eastings.html  | 26 ++++++++++++++++++++++++++
 urls.py                  |  1 +
 4 files changed, 42 insertions(+), 4 deletions(-)
 create mode 100644 templates/eastings.html

diff --git a/core/views/statistics.py b/core/views/statistics.py
index 395858b..99af707 100644
--- a/core/views/statistics.py
+++ b/core/views/statistics.py
@@ -12,7 +12,7 @@ from django.utils import timezone
 #from django.views.generic.list import ListView
 
 from troggle.core.models.troggle import Expedition, Person, PersonExpedition, DataIssue
-from troggle.core.models.caves import Cave, LogbookEntry
+from troggle.core.models.caves import Cave, LogbookEntry, Entrance
 from troggle.core.models.survex import SurvexBlock
 
 import troggle.settings as settings
@@ -157,3 +157,14 @@ def dataissues(request):
     dilist.sort(key = myFunc)        
  
     return render(request,'dataissues.html',  {'didict': dilist})
+
+def eastings(request):
+    '''report each Northing/Easting pair wherever recorded
+    '''
+    ents = []
+    entrances = Entrance.objects.all()
+    for e in entrances:
+        if e.easting or e.northing:
+            ents.append(e)
+ 
+    return render(request,'eastings.html',  {'ents': ents})
diff --git a/settings.py b/settings.py
index 218c27d..a73e437 100644
--- a/settings.py
+++ b/settings.py
@@ -98,9 +98,9 @@ LOGBOOK_PARSER_SETTINGS = {
                 "1992": ("1992/log.htm", "Parseloghtml01"), 
                 "1991": ("1991/log.htm", "Parseloghtml01"), 
                 "1990": ("1990/log.htm", "Parseloghtml01"), 
-                "1989": ("1989/log.htm", "Parseloghtml01"), 
-                "1988": ("1988/log.htm", "Parseloghtml01"), 
-                "1987": ("1987/log.htm", "Parseloghtml01"), 
+                "1989": ("1989/log.htm", "Parseloghtml01"), #crashes MySQL
+                "1988": ("1988/log.htm", "Parseloghtml01"), #crashes MySQL
+                "1987": ("1987/log.htm", "Parseloghtml01"), #crashes MySQL
                 "1985": ("1985/log.htm", "Parseloghtml01"), 
                 "1984": ("1984/log.htm", "Parseloghtml01"), 
                 "1983": ("1983/log.htm", "Parseloghtml01"), 
diff --git a/templates/eastings.html b/templates/eastings.html
new file mode 100644
index 0000000..92c69ba
--- /dev/null
+++ b/templates/eastings.html
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+{% block title %}Cave Entrance locations in UTM{% endblock %}
+
+{% block content %}
+
+<h1>Entrance locations</h1>
+
+<p>
+This is work in progress (May 2021).
+
+<table>
+<tr><th>Entrance</th><th>Easting</th><th>Northing</th><th>tag</th><th>tag exact</th><th>tag other</th></tr>
+{% for ent in ents %}
+<tr>
+  <td style="text-align:left"><a href="{{ ent.name }}">{{ent.name|safe}}</a></td>
+  <td style="text-align:right">{{ent.easting|floatformat:2}}</td>
+  <td style="text-align:right">{{ent.northing|floatformat:2}}</td>
+  <td style="text-align:right">{{ent.tag_station}}</td>
+  <td style="text-align:right">{{ent.exact_station}}</td>
+  <td style="text-align:right">{{ent.other_station}}</td>
+</tr>
+{% endfor %}
+</table>
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/urls.py b/urls.py
index c83bfdb..d920cef 100644
--- a/urls.py
+++ b/urls.py
@@ -132,6 +132,7 @@ trogglepatterns = [
     path('stats',       statistics.stats, name="stats"),
     path('pathsreport', statistics.pathsreport, name="pathsreport"),
     path('dataissues',  statistics.dataissues,  name="dataissues"),
+    path('eastings',    statistics.eastings,  name="eastings"),
 
     path('troggle',            frontpage,     name="frontpage"), # control panel. Shows recent actions.
     path('todo/<path:module>', todos,         name="todos"),