summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index b61eb0e..765e834 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -28,7 +28,7 @@ from troggle.parsers.scans import contentsjson
from troggle.core.models.troggle import DataIssue
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
-from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock
+from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock, SurvexFile
from troggle.core.views.scans import oldwallet, walletindex
from troggle.core.views.caves import getCave
@@ -240,8 +240,10 @@ def scanupload(request, path=None):
actual_saved = []
def read_json():
+ '''Read JSON from the wallet metadata file in the repo
+ or fills with blank data if that files can't be read'''
if contents_path.is_file():
- create = False # yes wallet exists becaue JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
+ create = False # yes wallet exists because JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
with open(contents_path) as json_file:
try:
waldata = json.load(json_file)
@@ -471,9 +473,9 @@ def scanupload(request, path=None):
svxfiles = []
checked = {}
context = {}
- if waldata:
+ if waldata: # should always be true as populated by blank data if json file doesn't exist
if not waldata["people"]:
- waldata["people"]=["NOBODY", "someone"]
+ waldata["people"]=["NOBODY"]
if not type(waldata["people"])==list:
if waldata["people"][0] == '"':
waldata["people"] = waldata["people"][1:-1]
@@ -486,6 +488,30 @@ def scanupload(request, path=None):
if waldata["name"]:
psg = waldata["name"]
+ if not waldata["date"]: # json file does not exist, blank data
+ # refactor into a separate function..
+ print(f'No date set')
+ refs=[]
+ dates = []
+ for svxf in waldata["survex file"]:
+ svx = Path(svxf)
+ if svx.suffix.lower() != ".svx":
+ svx = svx.with_suffix(".svx")
+ #print(f'{svx=}')
+ f = Path(settings.SURVEX_DATA) / svx
+ if f.is_file():
+ path = svx.parent / svx.stem
+ print(f' - {path=}')
+ svxfile = SurvexFile.objects.get(path=path)
+ blocks = SurvexBlock.objects.filter(survexfile= svxfile)
+ for b in blocks:
+ print(f' - - {b=} {b.scanswallet=} {b.date=}')
+ refs.append(b.scanswallet)
+ dates.append(b.date)
+ waldata["date"] = min(dates).isoformat()
+ for w in refs:
+ if w.walletname != wallet:
+ print(f'! Not the same wallet {wallet} in *ref {w.walletname=}')
#Survex and survex complaints
complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl)