summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-02-26 22:13:37 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-02-26 22:13:37 +0000
commit6de4fa66a2ea7986230c3bb0f64887488acaa33f (patch)
tree8907e1988764da4b090636b1efeee79021af7c9e
parent394d94d5d6916b3aa61c7f89ce1b37798d3a87a1 (diff)
downloadtroggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.tar.gz
troggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.tar.bz2
troggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.zip
Initial add of On This Day links to svx file page
-rw-r--r--core/models/caves.py2
-rw-r--r--core/models/survex.py12
-rw-r--r--core/views/survex.py40
-rw-r--r--parsers/survex.py2
-rw-r--r--templates/logbookentry.html42
-rw-r--r--templates/onthisdate.html42
-rw-r--r--templates/svxfile.html15
-rw-r--r--templates/wallet_table.html2
-rw-r--r--templates/walletform.html2
9 files changed, 104 insertions, 55 deletions
diff --git a/core/models/caves.py b/core/models/caves.py
index dffd670..1de5ef9 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -32,6 +32,8 @@ todo = """
foreign keys work fine ?!
- Why do we have CaveAndEntrance objects ? Surely entranceletter belong son the Entrance object?
+
+- move the aliases list from the code and put into an editable file
- Restore constraint: unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
"""
diff --git a/core/models/survex.py b/core/models/survex.py
index 338a235..c6d6af1 100644
--- a/core/models/survex.py
+++ b/core/models/survex.py
@@ -1,6 +1,7 @@
import os
import re
from urllib.parse import urljoin
+from pathlib import Path
from django.conf import settings
from django.db import models
@@ -39,8 +40,8 @@ class SurvexFile(models.Model):
# return "[SurvexFile:"+str(self.path) + "-" + str(self.survexdirectory) + "-" + str(self.cave)+"]"
def exists(self):
- fname = os.path.join(settings.SURVEX_DATA, self.path + ".svx")
- return os.path.isfile(fname)
+ fname = Path(settings.SURVEX_DATA, self.path + ".svx")
+ return fname.is_file()
def OpenFile(self):
fname = os.path.join(settings.SURVEX_DATA, self.path + ".svx")
@@ -64,6 +65,8 @@ class SurvexFile(models.Model):
class SurvexStationLookUpManager(models.Manager):
+ """Don't know what this does,
+ https://docs.djangoproject.com/en/dev/topics/db/managers/"""
def lookup(self, name):
blocknames, sep, stationname = name.rpartition(".")
return self.get(block=SurvexBlock.objects.lookup(blocknames), name__iexact=stationname)
@@ -99,9 +102,8 @@ class SurvexStation(models.Model):
# Single SurvexBlock
#
class SurvexBlockLookUpManager(models.Manager):
- """Don't know what this does, suspect it is part of the Django admin
- system"""
-
+ """Don't know what this does,
+ https://docs.djangoproject.com/en/dev/topics/db/managers/ """
def lookup(self, name):
if name == "":
blocknames = []
diff --git a/core/views/survex.py b/core/views/survex.py
index 3575bc9..70f4616 100644
--- a/core/views/survex.py
+++ b/core/views/survex.py
@@ -6,6 +6,8 @@ import socket
from pathlib import Path
from django import forms
+from django.db import models
+
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.http import HttpResponse
from django.shortcuts import render
@@ -13,14 +15,20 @@ from django.views.decorators.csrf import ensure_csrf_cookie
import troggle.settings as settings
from troggle.core.models.caves import Cave
+from troggle.core.models.survex import SurvexFile, SurvexBlock
from troggle.core.utils import only_commit
"""Everything that views survexfiles
but also displays data on a cave or caves when there is ambiguity
"""
-todo = """survexcavesingle is not properly producing any result for Homecoming, 1626-359, 2018-dm-07
+todo = """- survexcavesingle is not properly producing any result for Homecoming, 1626-359, 2018-dm-07
even though there are dozens of surveys.
+
+- Never actual uses the object for the survexfile, works entirely from the filepath! Make it check and validate
+
+- Save the edited survexfile as a survexfile object and re-parse it, and update
+all its dependencies
"""
survexdatasetpath = Path(settings.SURVEX_DATA)
@@ -107,6 +115,7 @@ class SvxForm(forms.Form):
datetime = forms.DateTimeField(widget=forms.TextInput(attrs={"readonly": True}))
outputtype = forms.CharField(widget=forms.TextInput(attrs={"readonly": True}))
code = forms.CharField(widget=forms.Textarea(attrs={"cols": 140, "rows": 36}))
+ survexfile = models.ForeignKey(SurvexFile, blank=True, null=True, on_delete=models.SET_NULL) # 1:1 ?
template = False
@@ -116,6 +125,16 @@ class SvxForm(forms.Form):
print(">>> >>> WARNING - svx file not found, showing TEMPLATE SVX", fname, flush=True)
self.template = True
return survextemplatefile
+ refs = SurvexFile.objects.filter(path=self.data["filename"])
+ if len(refs)==1:
+ self.survexfile = SurvexFile.objects.get(path=self.data["filename"])
+ else:
+ self.survexfile = refs[0]
+ # OK this is due to a bug in the import file parsing, whoops.
+ print("BUG - to be fixed in the survex parser - not critical..")
+ print(f"Number of SurvexFile objects found: {len(refs)}")
+ for s in refs:
+ print (s.path, s.survexdirectory, s.cave)
try:
fin = open(fname, "r", encoding="utf8", newline="")
svxtext = fin.read()
@@ -215,12 +234,12 @@ def svx(request, survex_file):
"""Displays a single survex file in an textarea window (using a javascript online editor to enable
editing) with buttons which allow SAVE, check for DIFFerences from saved, and RUN (which runs the
cavern executable and displays the output below the main textarea).
- Requires CSRF to be set up correct;ly, and requires permission to write to the filesystem.
+ Requires CSRF to be set up correctly, and requires permission to write to the filesystem.
"""
warning = False
# get the basic data from the file given in the URL
- dirname = os.path.split(survex_file)[0]
+ dirname = os.path.split(survex_file)[0] # replace with proper pathlib function..
dirname += "/"
nowtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
outputtype = "normal"
@@ -273,11 +292,24 @@ def svx(request, survex_file):
# print [ form.data['code'] ]
svxincludes = re.findall(r"(?i)\*include\s+(\S+)", form.data["code"] or "")
+ svxfile = form.survexfile # only valid once form.GetDiscCode() called
+ try:
+ svxblocksall = svxfile.survexblock_set.all()
+ except AttributeError: # some survexfiles just *include files and have no blocks themselves
+ svxblocksall = []
+ svxblocks = []
+ for b in svxblocksall:
+ if b.date:
+ svxblocks.append(b)
+ print(f"{svxfile=} {svxblocks}")
+
+
vmap = {
"settings": settings,
"warning": warning,
"has_3d": (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file(),
"title": survex_file,
+ "svxblocks": svxblocks,
"svxincludes": svxincludes,
"difflist": difflist,
"logmessage": logmessage,
@@ -521,7 +553,7 @@ def survexcavesingle(request, survex_cave):
def check_cave_registered(area, survex_cave):
"""Checks whether a cave has been properly registered when it is found in the Loser repo
- This should really be called by Databasereset not here in a view
+ This should really be called by databaseReset not here in a view
Currently Caves are only registered if they are listed in :expoweb: settings.CAVEDESCRIPTIONS
so we need to add in any more here.
diff --git a/parsers/survex.py b/parsers/survex.py
index b88267a..3cf3168 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -126,7 +126,7 @@ def get_team_on_trip(survexblock):
if survexblock in trip_people_cache:
return trip_people_cache[survexblock]
- qpeople = SurvexPersonRole.objects.filter(survexblock=survexblock)
+ qpeople = SurvexPersonRole.objects.filter(survexblock=survexblock) # not very good Django style
trip_people_cache[survexblock] = qpeople # this is a query list
return qpeople
diff --git a/templates/logbookentry.html b/templates/logbookentry.html
index 6fff583..2fdfb41 100644
--- a/templates/logbookentry.html
+++ b/templates/logbookentry.html
@@ -71,46 +71,6 @@
</div>
<span style="font-family: monospace; font-size: 150%; ">
-
- {% if svxothers %}<u>Survex files</u> on this date:<br>
- <span style="font-size: 70%; ">
- {% for item in svxothers %}
- {% if item.isSurvexBlock %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="/survexfile/{{item.survexfile.path}}">{{item.survexfile.path|safe}}</a><br/>{% endif %}
- {% empty %}
- <em>None found for this date.</em><br>
- {% endfor %}
- </span>
- {% else %}
- <em>No survex files found for this date.</em><br>
- {% endif %}
- {% if wallets %}<u>Wallets</u> on this date:<br>
- <span style="font-size: 70%; ">
- {% for item in wallets %}
- &nbsp;&nbsp;&nbsp;&nbsp;<a href="/survey_scans/{{item.walletname|urlencode}}/">{{item.walletname|safe}}</a>
- {% if item.name %}
- {{item.name|safe}} <br/>
- {% else %}
- {{item.get_fnames|safe}}
- <br/>
- {% endif %}
- {% empty %}
- <em>None found for this date.</em><br>
- {% endfor %}
- </span>
- {% else %}
- <em>No wallets files found for this date.</em><br>
- {% endif %}
- {% if trips %}<u>All logbook trips</u> on this date:<br>
- <span style="font-size: 70%; ">
- {% for item in trips %}
- {% if item.isLogbookEntry %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{item.get_absolute_url}}">{{item.title|safe}}</a><br/>{% endif %}
- {% empty %}
- <em>None found for this date, but there should be..</em><br>
- {% endfor %}
- </span>
- {% else %}
- <em>Hmm...</em><br>
- {% endif %}
-
+ {% include 'onthisdate.html' %}
</span>
{% endblock %}
diff --git a/templates/onthisdate.html b/templates/onthisdate.html
new file mode 100644
index 0000000..dd75144
--- /dev/null
+++ b/templates/onthisdate.html
@@ -0,0 +1,42 @@
+<!-- this is an INCLUDED template onthisdate.html-->
+
+ {% if svxothers %}<u>Survex files</u> on this date:<br>
+ <span style="font-size: 70%; ">
+ {% for item in svxothers %}
+ {% if item.isSurvexBlock %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="/survexfile/{{item.survexfile.path}}">{{item.survexfile.path|safe}}</a><br/>{% endif %}
+ {% empty %}
+ <em>None found for this date.</em><br>
+ {% endfor %}
+ </span>
+ {% else %}
+ <em>No survex files found for this date.</em><br>
+ {% endif %}
+ {% if wallets %}<u>Wallets</u> on this date:<br>
+ <span style="font-size: 70%; ">
+ {% for item in wallets %}
+ &nbsp;&nbsp;&nbsp;&nbsp;<a href="/survey_scans/{{item.walletname|urlencode}}/">{{item.walletname|safe}}</a>
+ {% if item.name %}
+ {{item.name|safe}} <br/>
+ {% else %}
+ {{item.get_fnames|safe}}
+ <br/>
+ {% endif %}
+ {% empty %}
+ <em>None found for this date.</em><br>
+ {% endfor %}
+ </span>
+ {% else %}
+ <em>No wallets files found for this date.</em><br>
+ {% endif %}
+ {% if trips %}<u>All logbook trips</u> on this date:<br>
+ <span style="font-size: 70%; ">
+ {% for item in trips %}
+ {% if item.isLogbookEntry %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{item.get_absolute_url}}">{{item.title|safe}}</a><br/>{% endif %}
+ {% empty %}
+ <em>None found for this date, but there should be..</em><br>
+ {% endfor %}
+ </span>
+ {% else %}
+ <em>Hmm...</em><br>
+ {% endif %}
+ \ No newline at end of file
diff --git a/templates/svxfile.html b/templates/svxfile.html
index 3417859..45e0127 100644
--- a/templates/svxfile.html
+++ b/templates/svxfile.html
@@ -80,6 +80,17 @@ LOGMESSAGES
-->
{% endif %}
</div>
-
-
+<span style="font-family: monospace; font-size: 130%; ">
+{% for sb in svxblocks %}
+<details {% if forloop.first %} open{% endif %}><summary><b>{{sb.date|date:"Y-m-d"}}</b> {{sb.title}} '{{sb.name}}'</summary>
+List of Logbook entries, wallets and other survex files on {{sb.date|date:"Y-m-d"}}.
+<br />
+[Work in progress, Feb. 2023...]<br />
+ {% include 'onthisdate.html' %}
+</details>
+{% empty %}
+Cannot find any survex blocks in this survex file. <br />
+Report this to a nerd if you think this is incorrect.
+{% endfor %}
+</span>
{% endblock %}
diff --git a/templates/wallet_table.html b/templates/wallet_table.html
index d5aead8..4e1c81b 100644
--- a/templates/wallet_table.html
+++ b/templates/wallet_table.html
@@ -1,4 +1,4 @@
-
+<!-- this is an INCLUDED template wallet_table.html-->
<table width=95%>
<tr><th>Wallet</th><th width=15%>Wallet Date</th><th>Cave</th><th>Wallet Name</th><th>Survex survey length</th>
diff --git a/templates/walletform.html b/templates/walletform.html
index 1583393..c35fa03 100644
--- a/templates/walletform.html
+++ b/templates/walletform.html
@@ -246,7 +246,7 @@
{% for item in svxothers %}
{% if item.isSurvexBlock %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="/survexfile/{{item.survexfile.path}}">{{item.survexfile.path|safe}}</a><br/>{% endif %}
{% empty %}
- <em>None found for this date, bit there should be..</em><br>
+ <em>None found for this date, but there should be..</em><br>
{% endfor %}
</span>
{% else %}