Initial add of On This Day links to svx file page

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

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.