From fea69c03717d700192d7a5a5afc4c27a654a923f Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 28 Jul 2022 01:48:22 +0300 Subject: Extend wallets by cave report --- core/views/uploads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/views/uploads.py') diff --git a/core/views/uploads.py b/core/views/uploads.py index b275d2a..62ed56e 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -93,7 +93,7 @@ xlate = {"url": "description url", "electronic": "electronic survey", "pland": "plan drawn", "elevd": "elev drawn", - "psg": "name", + "psg": "name", # not real ? "survex": "survex file", } -- cgit v1.2.3 From c29e240c2b6f3ced17bdd42de107215431c7d19d Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 28 Jul 2022 18:36:40 +0300 Subject: creating new wallet now copies nd commits --- core/views/uploads.py | 36 ++++++++++++++++++++++++++---------- parsers/scans.py | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'core/views/uploads.py') diff --git a/core/views/uploads.py b/core/views/uploads.py index 62ed56e..500e4bd 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -23,12 +23,12 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned #from troggle import settings from troggle.parsers.imports import import_caves, import_people, import_surveyscans from troggle.parsers.imports import import_logbooks, import_QMs, import_drawingsfiles, import_survex -from troggle.parsers.scans import wallet_blank_json, wallet_blank_html, contentsjson, indexhtml +from troggle.parsers.scans import wallet_blank_json, wallet_blank_html, contentsjson, indexhtml, CopyWalletData # from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time* 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 +from troggle.core.models.survex import DrawingFile, Wallet from troggle.core.views.scans import oldwallet, walletindex from troggle.core.views.caves import getCave @@ -93,7 +93,7 @@ xlate = {"url": "description url", "electronic": "electronic survey", "pland": "plan drawn", "elevd": "elev drawn", - "psg": "name", # not real ? + "psg": "name", # a name for this wallet "survex": "survex file", } @@ -115,13 +115,14 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way waldata["survex file"] = [waldata["survex file"]] for svx in waldata["survex file"]: - svxfiles.append(svx) - if not (Path(settings.SURVEX_DATA) / svx).is_file(): - file_complaint = f"{wallet} Incorrect survex file name in wallet data: {svx} not found in LOSER repo" - complaints.append(file_complaint) - message = f"! {file_complaint}" - print(message) - DataIssue.objects.create(parser='scans', message=message, url=wurl) # set URL to this wallet folder + if svx !="": + svxfiles.append(svx) + if not (Path(settings.SURVEX_DATA) / svx).is_file(): + file_complaint = f"{wallet} Incorrect survex file name in wallet data: {svx} not found in LOSER repo" + complaints.append(file_complaint) + message = f"! {file_complaint}" + print(message) + DataIssue.objects.create(parser='scans', message=message, url=wurl) # set URL to this wallet folder if waldata["survex not required"] and waldata["survex file"] != "": survex_complaint = "Survex is stated as not required and yet there is a survex file!" @@ -290,6 +291,21 @@ def scanupload(request, path=None): with open(contents_path, "w") as jfile: json.dump(wd, jfile, indent = 1) # print(f'--- FINISHED saving to JSON\n') + + # This copies the new data to the drawings repo and commit it + # needs the troggle object wallet, not a string + + try: + w, created = Wallet.objects.get_or_create(walletname=wallet) + print(f'wallet string {wallet}, wallet object {w} created new?: {created}') + if created: + w.fpath = Path(settings.SCANS_ROOT, wallet[0:4], wallet) + w.save() + CopyWalletData(w) + except: + print(f'wallet string {wallet}, FAIL TO GET WALLET OBJECT, maybe we need to create it ?') + raise + else: print(f'--- INVALID JSON Update form submitted') print(formj.errors) diff --git a/parsers/scans.py b/parsers/scans.py index c75b7f2..8b8f92f 100644 --- a/parsers/scans.py +++ b/parsers/scans.py @@ -80,6 +80,8 @@ def LoadListScansFile(wallet): c = 0 def CopyWalletData(wallet): '''Copies all the contents.json to a parallel set of folders in the drawings repo + refreshes everything during a ful import, but it shoudl all be up to date as every time + wallet data gets saved it should also be copied across and committed. ''' year = wallet.walletname[0:4] destfolder = Path(settings.DRAWINGS_DATA,'walletjson', year, wallet.walletname) -- cgit v1.2.3 From 129ea3cc5bd9a77db9138277e2dc23b294c19608 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 1 Aug 2022 02:50:19 +0300 Subject: debugging ticklist --- core/models/survex.py | 117 ++++++++++++++++++++++++++++++++++++++++++- core/views/scans.py | 22 ++++---- core/views/uploads.py | 10 ++-- templates/personwallets.html | 43 ++++++++++++++++ templates/walletform.html | 4 +- 5 files changed, 180 insertions(+), 16 deletions(-) (limited to 'core/views/uploads.py') diff --git a/core/models/survex.py b/core/models/survex.py index a562a44..11ef4f4 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -1,8 +1,10 @@ import os import re import json +import operator from urllib.parse import urljoin from pathlib import Path +from functools import reduce from django.db import models from django.conf import settings @@ -177,7 +179,7 @@ class Wallet(models.Model): def get_json(self): jsonfile = Path(self.fpath, 'contents.json') if not Path(jsonfile).is_file(): - print(f'{jsonfile} is not a file') + #print(f'{jsonfile} is not a file') return None else: with open(jsonfile) as json_f: @@ -186,7 +188,7 @@ class Wallet(models.Model): except: wurl = f"/scanupload/{self.walletname}" # .replace('#', ':') message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file" - print(message) + #print(message) raise return waldata @@ -225,7 +227,118 @@ class Wallet(models.Model): return None jsondata = self.get_json() return jsondata["name"] + + def get_fnames(self): + '''Filenames without the suffix, i.e. without the ".jpg" + ''' + dirpath = Path(settings.SCANS_ROOT, self.fpath) + files = [] + if dirpath.is_dir(): + try: + for f in dirpath.iterdir(): + if f.is_file(): + if f.name != 'contents.json' and f.name != 'walletindex.html': + files.append(Path(f.name).stem) + except FileNotFoundError: + pass + return files + + + def get_ticks(self): + waldata = self.get_json() + if not waldata: + return {} + ticks = {} + + # Initially, are there any required survex files present ? + survexok = "red" + ticks["S"] = "red" + if waldata["survex not required"]: + survexok = "green" + ticks["S"] = "green" + else: + if waldata["survex file"]: + if not type(waldata["survex file"])==list: # a string also is a sequence type, so do it this way + waldata["survex file"] = [waldata["survex file"]] + ngood = 0 + nbad = 0 + ticks["S"] = "lightblue" + for svx in waldata["survex file"]: + if svx !="": + if (Path(settings.SURVEX_DATA) / svx).is_file(): + ngood += 1 + else: + nbad += 1 + if nbad == 0 and ngood >= 1: + ticks["S"] = "green" + if nbad >= 1 and ngood >= 1: + ticks["S"] = "orange" + if nbad >= 1 and ngood == 0: + ticks["S"] = "red" + + # Cave Description + if waldata["description written"]: + ticks["C"] = "green" + else: + ticks["C"] = survexok + # QMs + if waldata["qms written"]: + ticks["Q"] = "green" + else: + ticks["Q"] = survexok + + # Notes, Plan, Elevation; Tunnel + if waldata["electronic survey"]: + ticks["N"] = "green" + ticks["P"] = "green" + ticks["E"] = "green" + ticks["T"] = "green" + else: + files = self.get_fnames() + print(self.walletname,files) + # Notes required + notes_scanned = reduce(operator.or_, [f.startswith("note") for f in files], False) + notes_scanned = reduce(operator.or_, [f.endswith("notes") for f in files], notes_scanned) + if notes_scanned: + ticks["N"] = "green" + else: + ticks["N"] = "red" + + # Plan drawing required + plan_scanned = reduce(operator.or_, [f.startswith("plan") for f in files], False) + plan_scanned = reduce(operator.or_, [f.endswith("plan") for f in files], plan_scanned) + plan_drawing_required = not (plan_scanned or waldata["plan drawn"] or waldata["plan not required"]) + if plan_drawing_required: + ticks["P"] = "red" + else: + ticks["P"] = "green" + + # Elev drawing required + elev_scanned = reduce(operator.or_, [f.startswith("elev") for f in files], False) + elev_scanned = reduce(operator.or_, [f.endswith("elev") for f in files], elev_scanned) + elev_scanned = reduce(operator.or_, [f.endswith("elevation") for f in files], elev_scanned) + elev_drawing_required = not (elev_scanned or waldata["elev drawn"] or waldata["elev not required"]) + if elev_drawing_required: + ticks["E"] = "red" + else: + ticks["E"] = "green" + + # Tunnel / Therion + if elev_drawing_required or plan_drawing_required: + ticks["T"] = "red" + else: + ticks["T"] = "green" + + + # Website + if waldata["website updated"]: + ticks["W"] = "green" + else: + ticks["W"] = "red" + + return ticks + def __str__(self): return "[" + str(self.walletname) + " (Wallet)]" diff --git a/core/views/scans.py b/core/views/scans.py index d7c48e2..94fb560 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -85,11 +85,13 @@ def walletslistperson(request, first_name, last_name): #personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower()) earliest = datetime.datetime.now().date() + manywallets = [] - wallets = Wallet.objects.all() + wallets = Wallet.objects.all() for w in wallets: w.persons = w.people() # ephemeral attribute for web page + w.ticks = {} # ephemeral tick boxes display # check if there is a json if not w.get_json(): populatewallet(w) @@ -102,18 +104,20 @@ def walletslistperson(request, first_name, last_name): nobody = wp[0].lower() if nobody == 'unknown' or nobody == 'nobody' or nobody == ' ': populatewallet(w) - + if w.persons: if p.fullname in w.persons: #found person manywallets.append(w) - if not w.date(): - datewallet(w, earliest) - - c = w.cave() - if not c: - caveifywallet(w) - + if not w.date(): + datewallet(w, earliest) + + c = w.cave() + if not c: + caveifywallet(w) + + w.ticks = w.get_ticks() # the complaints in colour form + return render(request, 'personwallets.html', { 'manywallets':manywallets, 'settings': settings, 'person': p}) def walletslistyear(request, year): diff --git a/core/views/uploads.py b/core/views/uploads.py index 500e4bd..685f7bf 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -100,6 +100,9 @@ xlate = {"url": "description url", def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): '''Taken from old script wallets.py and edited to make more comprehensible Loads the survex files names and processes all complaints + + All needs to be restructred to use the get_ticks() function on the Wallets class in core/models/survex.py + which does the same thing ''' # Date if not waldata["date"]: @@ -134,20 +137,21 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): # Notes required if not waldata["electronic survey"]: notes_scanned = reduce(operator.or_, [f.startswith("note") for f in files], False) - notes_scanned = reduce(operator.or_, [f.endswith("note") for f in files], notes_scanned) + notes_scanned = reduce(operator.or_, [Path(f).stem.endswith("notes") for f in files], notes_scanned) if not notes_scanned: complaints.append("The notes needs scanning (or renaming): no noteNN.jpg or XXnote.jpg file found; and this is not an electronic survey.") # Plan drawing required plan_scanned = reduce(operator.or_, [f.startswith("plan") for f in files], False) - plan_scanned = reduce(operator.or_, [f.endswith("plan") for f in files], plan_scanned) + plan_scanned = reduce(operator.or_, [Path(f).stem.endswith("plan") for f in files], plan_scanned) plan_drawing_required = not (plan_scanned or waldata["plan drawn"] or waldata["plan not required"]) if plan_drawing_required: complaints.append("The plan needs drawing (or renaming, or tick 'Plan drawn' checkbox or 'Plan not required' checkbox): no planNN.jpg or XXplan.jpg file found.") # Elev drawing required elev_scanned = reduce(operator.or_, [f.startswith("elev") for f in files], False) - elev_scanned = reduce(operator.or_, [f.endswith("elev") for f in files], elev_scanned) + elev_scanned = reduce(operator.or_, [Path(f).stem.endswith("elev") for f in files], elev_scanned) + elev_scanned = reduce(operator.or_, [Path(f).stem.endswith("elevation") for f in files], elev_scanned) elev_drawing_required = not (elev_scanned or waldata["elev drawn"] or waldata["elev not required"]) if elev_drawing_required: complaints.append("The elevation needs drawing (or renaming, or tick 'Elev drawn' checkbox or 'Elev not required' checkbox): no elevNN.jpg or XXelev.jpg file found.") diff --git a/templates/personwallets.html b/templates/personwallets.html index 27c6db8..5586485 100644 --- a/templates/personwallets.html +++ b/templates/personwallets.html @@ -14,6 +14,48 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
  • per year, e.g. 2019
  • per cave, e.g. 1623/161 + + + + + + + + + + + + + + + + + + + + +{% for wallet in manywallets|dictsort:"walletname" %} + + + + + + + + + + + + + + + + + + +{% endfor %} +
    WalletWallet DateCaveWallet NameSCQNPETW
    {{wallet.walletname}}{{wallet.date}}{{wallet.cave}}{{wallet.name}}        
    +
    {% for wallet in manywallets|dictsort:"walletname" %} @@ -43,4 +85,5 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c {% endfor %}
    WalletWallet DateWallet NameOther PeopleCaveScansSurvex blocksDrawings using these scans
    + {% endblock %} \ No newline at end of file diff --git a/templates/walletform.html b/templates/walletform.html index 0bde7be..37b1c11 100644 --- a/templates/walletform.html +++ b/templates/walletform.html @@ -156,10 +156,10 @@
    - +
    - +
    -- cgit v1.2.3