2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

Initial add of On This Day links to svx file page

This commit is contained in:
Philip Sargent 2023-02-26 22:13:37 +00:00
parent 394d94d5d6
commit 6de4fa66a2
9 changed files with 104 additions and 55 deletions

View File

@ -33,6 +33,8 @@ todo = """
- 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"))
"""

View File

@ -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 = []

View File

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

View File

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

View File

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

42
templates/onthisdate.html Normal file
View File

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

View File

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

View File

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

View File

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