summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2022-09-20 01:02:06 +0300
committerPhilip Sargent <philip.sargent@klebos.com>2022-09-20 01:02:06 +0300
commit61f9863a068a0e2d128a100088cf42c0c61c97ab (patch)
tree567baea54e0f3f4ef0f54842588fbdf558a2dc4f /core
parent47878d264b05aaed621be6dfa52887fa4fe76cb4 (diff)
downloadtroggle-61f9863a068a0e2d128a100088cf42c0c61c97ab.tar.gz
troggle-61f9863a068a0e2d128a100088cf42c0c61c97ab.tar.bz2
troggle-61f9863a068a0e2d128a100088cf42c0c61c97ab.zip
bug fixes and coping with a list of cave ids in JSON
Diffstat (limited to 'core')
-rw-r--r--core/models/survex.py2
-rw-r--r--core/views/scans.py4
-rw-r--r--core/views/uploads.py28
3 files changed, 23 insertions, 11 deletions
diff --git a/core/models/survex.py b/core/models/survex.py
index af948b8..f2ba667 100644
--- a/core/models/survex.py
+++ b/core/models/survex.py
@@ -161,7 +161,7 @@ class SurvexPersonRole(models.Model):
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)
def __str__(self):
- return str(self.person) + " - " + str(self.survexblock)
+ return str(self.personname) + " - " + str(self.survexblock)
class Wallet(models.Model):
'''We do not keep the JSON values in the database, we query them afresh each time,
diff --git a/core/views/scans.py b/core/views/scans.py
index ceda72b..f641423 100644
--- a/core/views/scans.py
+++ b/core/views/scans.py
@@ -84,7 +84,7 @@ def fillblankpeople(w):
w.persons = wp
if len(wp) == 1:
nobody = wp[0].lower()
- if nobody == 'unknown' or nobody == 'nobody' or nobody == ' ':
+ if nobody == 'unknown' or nobody == 'nobody' or nobody == ' ' or nobody == '':
populatewallet(w)
def fillblankothers(w):
@@ -93,7 +93,7 @@ def fillblankothers(w):
datewallet(w, earliest)
c = w.cave()
- if not c:
+ if not c or c == "":
caveifywallet(w)
def fixsurvextick(w, ticks):
diff --git a/core/views/uploads.py b/core/views/uploads.py
index 5515982..8c8721b 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -205,8 +205,13 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
if waldata["cave"]:
try:
caveid = waldata["cave"]
- caveid = caveid.replace("/","-")
- caveobject = getCave(caveid)
+ if type(caveid) is list:
+ for i in caveid:
+ i = i.replace("/","-")
+ caveobject = getCave(i) # only th elast one gets recorded.. ouch.
+ else:
+ caveid = caveid
+ caveobject = getCave(caveid)
print(f'getCave for id "{waldata["cave"]}" {caveobject}')
# if not caveobject.url == waldata["description url"]:
# complaints.append(f'The URL of cave description \"{waldata["description url"]}\" does not match the one on record for this cave which is: "{caveobject.url}". If the wallet is not for a cave, put a useful URL here.')
@@ -248,7 +253,9 @@ def scanupload(request, path=None):
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'''
+ or fills with blank data if that files can't be read
+
+ Should sanitise to ensure no spurious backslashes e.g. in windows style paths'''
waldata = {}
if contents_path.is_file():
create = False # yes wallet exists because JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
@@ -477,9 +484,12 @@ def scanupload(request, path=None):
if dirs:
dirs = sorted(dirs)
-
- waldata = read_json()
-
+ try:
+ waldata = read_json()
+ except:
+ message = f'Nasty failure in parsing wallets metadata in {contents_path}. Probably backslash not forward slash in filename path'
+ return render(request, 'errors/generic.html', {'message': message})
+
jsonfile = Path(settings.DRAWINGS_DATA, "walletjson") / wallet[0:4] / wallet / "contents.json"
# print(f'! - FORM scanupload - jsonfile {jsonfile}')
if not Path(jsonfile).is_file():
@@ -501,8 +511,8 @@ def scanupload(request, path=None):
# waldata["people"] = list(waldata["people"])
- if not waldata["date"] or not waldata["people"] or waldata["people"] == ["Unknown"]: # json file does not exist, blank data, or people not typed into JSON file
- # refactor into separate functions for no date set or no people set
+ if not waldata["date"] or not waldata["people"] or waldata["people"] == ["Unknown"] or waldata["people"] == [""] or waldata["cave"] == "": # json file does not exist, blank data, or people not typed into JSON file
+ # refactor into separate functions for no date set or no people set or no cave set
# print(f'No date set')
print(f'\n - Incomplete, empty or default wallet data {wallet} {waldata=}')
refs=[]
@@ -551,11 +561,13 @@ def scanupload(request, path=None):
QSpeople = SurvexPersonRole.objects.filter(survexblock=b)
print(f' - - {QSpeople=}')
for p in QSpeople:
+ print(f' - - {p.personname} ')
team.append(p.personname)
# else:
# print(f' - Wallet not matching *ref {b.scanswallet=} {wallet}')
if dates:
waldata["date"] = min(dates).isoformat()
+ print(f' - - {team=} ')
team = list(set(team))
waldata["people"] = team