diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2022-07-28 01:48:22 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2022-07-28 01:48:22 +0300 |
commit | fea69c03717d700192d7a5a5afc4c27a654a923f (patch) | |
tree | 5117664c19999fd1bf3dab22f8d631c0aa7dbbd9 /core/models | |
parent | dd0fcc28ddc4768fb8fa3edcec32ee205d77101b (diff) | |
download | troggle-fea69c03717d700192d7a5a5afc4c27a654a923f.tar.gz troggle-fea69c03717d700192d7a5a5afc4c27a654a923f.tar.bz2 troggle-fea69c03717d700192d7a5a5afc4c27a654a923f.zip |
Extend wallets by cave report
Diffstat (limited to 'core/models')
-rw-r--r-- | core/models/caves.py | 10 | ||||
-rw-r--r-- | core/models/survex.py | 34 |
2 files changed, 40 insertions, 4 deletions
diff --git a/core/models/caves.py b/core/models/caves.py index 8cd658c..f5ae320 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -26,6 +26,14 @@ from django.shortcuts import render from troggle.core.models.troggle import TroggleModel, Person, Expedition, DataIssue from troggle.core.models.survex import SurvexStation from troggle.core.utils import writetrogglefile +from troggle.core.utils import TROG + +# Us ethe TROG global object to cache teh cave lookup list +Gcavelookup = TROG['caves']['gcavelookup'] +Gcave_count = TROG['caves']['gcavecount'] + +Gcavelookup = None +Gcave_count = None '''The model declarations for Areas, Caves and Entrances. Also LogBookENtry, QM, PersonTrip ''' @@ -564,8 +572,6 @@ class PersonTrip(TroggleModel): return f'{self.personexpedition} ({self.logbook_entry.date})' -Gcavelookup = None -Gcave_count = None def GetCaveLookup(): """A very relaxed way of finding probably the right cave given almost any string which might serve to identify it diff --git a/core/models/survex.py b/core/models/survex.py index 1273a8b..9746afb 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -1,6 +1,8 @@ import os -from urllib.parse import urljoin import re +import json +from urllib.parse import urljoin +from pathlib import Path from django.db import models from django.conf import settings @@ -160,6 +162,9 @@ class SurvexPersonRole(models.Model): return str(self.person) + " - " + str(self.survexblock) class Wallet(models.Model): + '''We do not keep the JSON values in the database, we query them afresh each time, + but we will change this when we need to do a Django query on e.g. personame + ''' fpath = models.CharField(max_length=200) walletname = models.CharField(max_length=200) @@ -169,6 +174,31 @@ class Wallet(models.Model): def get_absolute_url(self): return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)})) + def get_json(self): + jsonfile = Path(self.fpath, 'contents.json') + if not Path(jsonfile).is_file(): + print(f'{jsonfile} is not a file') + return None + else: + with open(jsonfile) as json_f: + try: + waldata = json.load(json_f) + except: + wurl = f"/scanupload/{self.walletname}" # .replace('#', ':') + message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file" + print(message) + raise + + return waldata + + def date(self): + jsondata = self.get_json() + return jsondata["date"] + + def name(self): + jsondata = self.get_json() + return jsondata["name"] + def __str__(self): return str(self.walletname) + " (Wallet)" @@ -189,7 +219,7 @@ class SingleScan(models.Model): class DrawingFile(models.Model): dwgpath = models.CharField(max_length=200) dwgname = models.CharField(max_length=200) - manywallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files + dwgwallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files dwgcontains = models.ManyToManyField("DrawingFile") # case when its a frame type filesize = models.IntegerField(default=0) |