From 6452a7beed18072719b27239b95cb7d081d81dc3 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 31 Aug 2022 12:09:07 +0300 Subject: [PATCH] fix green block for survex files on table --- core/models/survex.py | 11 +++++++++-- core/views/drawings.py | 2 +- core/views/scans.py | 12 +++++++++--- core/views/uploads.py | 17 ++++++++++++----- templates/walletform.html | 7 +++++-- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index fe39136..85e9717 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -177,7 +177,7 @@ class Wallet(models.Model): return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)})) def get_json(self): - jsonfile = Path(self.fpath, 'contents.json') + #jsonfile = Path(self.fpath, 'contents.json') # Get from git repo instead # :drawings: walletjson/2022/2022#01/contents.json @@ -251,7 +251,14 @@ class Wallet(models.Model): except FileNotFoundError: pass return files - + + def fixsurvextick(self, tick): + blocks = SurvexBlock.objects.filter(scanswallet = self) + result = tick + for b in blocks: + if b.survexfile: # if any exist in db, no check for validity or a real file. Refactor. + result = "seagreen" # slightly different shade of green + return result def get_ticks(self): ticks = {} diff --git a/core/views/drawings.py b/core/views/drawings.py index 5e60130..93a5573 100644 --- a/core/views/drawings.py +++ b/core/views/drawings.py @@ -42,7 +42,7 @@ def dwgfilesingle(request, path): webpage /dwgupload/... if the user types the filename into the browser bar. Could be a problem? Should we validate using uploads.py dwgvaliddisp() here too? ''' - tfile = Path(settings.DRAWINGS_DATA, path) + tfile = Path(settings.DRAWINGS_DATA, path.replace(":","#")) if not tfile.is_file(): message = f'Drawing file not found in filesystem at \'{path}\' .' return render(request, 'errors/generic.html', {'message': message}) diff --git a/core/views/scans.py b/core/views/scans.py index ddaf9ae..78f436f 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -95,8 +95,11 @@ def fillblankothers(w): c = w.cave() if not c: caveifywallet(w) - +def fixsurvextick(w, ticks): + ticks["S"] = w.fixsurvextick(ticks["S"]) + + def walletslistperson(request, first_name, last_name): '''Page which displays a list of all the wallets for a specific person HORRIBLE linear search through everything. Index and do SQL query properly @@ -114,6 +117,7 @@ def walletslistperson(request, first_name, last_name): manywallets.append(w) fillblankothers(w) w.ticks = w.get_ticks() # the complaints in colour form + fixsurvextick(w, w.ticks) return manywallets try: @@ -143,7 +147,8 @@ def walletslistyear(request, year): manywallets.append(w) fillblankpeople(w) fillblankothers(w) - w.ticks = w.get_ticks() # the complaints in colour form + w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc + fixsurvextick(w, w.ticks) else: continue @@ -177,7 +182,8 @@ def cavewallets(request, caveid): for w in manywallets: fillblankpeople(w) fillblankothers(w) - w.ticks = w.get_ticks() # the complaints in colour form + w.ticks = w.get_ticks() # the complaints in colour form, from the json file on disc + fixsurvextick(w, w.ticks) return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave}) diff --git a/core/views/uploads.py b/core/views/uploads.py index f46db92..860cba7 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -240,7 +240,7 @@ def scanupload(request, path=None): git = settings.GIT filesaved = False 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''' @@ -472,7 +472,12 @@ def scanupload(request, path=None): waldata = read_json() - cave ="" + jsonfile = Path(settings.DRAWINGS_DATA, "walletjson") / wallet[0:4] / wallet / "contents.json" + print(f'! - FORM scanupload - jsonfile {jsonfile}') + if not Path(jsonfile).is_file(): + metadataurl = "" + else: + metadataurl = Path("/dwgdataraw", "walletjson") / wallet[0:4] / wallet.replace("#",":") / "contents.json" psg = "" chkplannr = "" chkpland = "" @@ -565,14 +570,16 @@ def scanupload(request, path=None): waldata["name"] = f"several, please edit: {names}" print(f' - More than one block name is relevant {names} in this wallet {wallet}. Not managed in this troggle release.') - if waldata["cave"]: + if "cave" in waldata: cave = waldata["cave"] # text string + else: + cave = "" if waldata["name"]: psg = waldata["name"] if not waldata["description url"]: waldata["description url"]="" - #Survex and survex complaints + #Survex and survex complaints, comes from json file on disc, not as pre-populated as above complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl) # print(f' - {caveobject=}') @@ -586,7 +593,7 @@ def scanupload(request, path=None): context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty, 'files': files, 'dirs': dirs, 'waldata': waldata, 'svxfiles': svxfiles, 'checked': checked, - 'create': create, + 'create': create, 'metadataurl': metadataurl, 'complaints': complaints, 'caveobject': caveobject, 'people': waldata["people"], 'peoplesize': str(len(str(waldata["people"]))), diff --git a/templates/walletform.html b/templates/walletform.html index 66d4955..d02c7e4 100644 --- a/templates/walletform.html +++ b/templates/walletform.html @@ -98,6 +98,7 @@ {% endif %}
+ {% if not create %}
@@ -112,9 +113,11 @@ {% for svx in svxfiles%} {{svx}} {% endfor %} - -

+ +
{% endif %} + {% if metadataurl %}Debug: json file
{% endif %} +