diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-02-26 22:13:37 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-02-26 22:13:37 +0000 |
commit | 6de4fa66a2ea7986230c3bb0f64887488acaa33f (patch) | |
tree | 8907e1988764da4b090636b1efeee79021af7c9e /core | |
parent | 394d94d5d6916b3aa61c7f89ce1b37798d3a87a1 (diff) | |
download | troggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.tar.gz troggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.tar.bz2 troggle-6de4fa66a2ea7986230c3bb0f64887488acaa33f.zip |
Initial add of On This Day links to svx file page
Diffstat (limited to 'core')
-rw-r--r-- | core/models/caves.py | 2 | ||||
-rw-r--r-- | core/models/survex.py | 12 | ||||
-rw-r--r-- | core/views/survex.py | 40 |
3 files changed, 45 insertions, 9 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. |