diff --git a/core/models/wallets.py b/core/models/wallets.py index 19eaec5..7c0dea4 100644 --- a/core/models/wallets.py +++ b/core/models/wallets.py @@ -13,6 +13,7 @@ from django.urls import reverse # from troggle.core.models.survex import SurvexBlock # from troggle.core.models.troggle import DataIssue # circular import. Hmm +YEAR_RANGE = (1975, 2050) class Wallet(models.Model): """We do not keep the JSON values in the database, we query them afresh each time, @@ -88,7 +89,8 @@ class Wallet(models.Model): if self.walletname[4] != "#": return None year = int(self.walletname[0:4]) - if year < 1975 or year > 2050: + ymin, ymax = YEAR_RANGE + if year < ymin or year > ymax: return None else: self.walletyear = datetime.date(year, 1, 1) diff --git a/core/views/wallets.py b/core/views/wallets.py index 9779b83..0d8ecd0 100644 --- a/core/views/wallets.py +++ b/core/views/wallets.py @@ -18,7 +18,7 @@ from troggle.core.models.caves import Cave from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole from troggle.core.models.troggle import DataIssue, Expedition -from troggle.core.models.wallets import Wallet +from troggle.core.models.wallets import Wallet, YEAR_RANGE from troggle.core.views.caves import getCave from troggle.core.views.scans import caveifywallet, oldwallet @@ -125,7 +125,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl): or waldata["people"] == [""] ): complaints.append( - "Someody must have done this. Look in the survex file, or in the logbook entries for this date, for the people who created this data." + "Somebody must have done this. Look in the survex file, or in the logbook entries for this date, for the people who created this data." ) # survex, but get_ticks has already done much of this ?? @@ -298,16 +298,17 @@ def walletedit(request, path=None): if not re.match("(19|20)\d\d[:#]\d\d\d?", wpath): return (None, get_next_empty() ) - if int(year) < 1977: - year = "1977" - if int(year) > 2050: + ymin, ymax = YEAR_RANGE + if int(year) < ymin: + year = str(ymin+2) + if int(year) > ymax: return (None, get_next_empty() ) wallet = f"{year}:{wnumber:02d}" return (None, wallet) def create_nav_links(wallet): - print(f" --- {wallet}") + print(f"--- {wallet} now current") y = wallet[:4] n = wallet[5:] nexty = f"{int(y)+1}" @@ -487,7 +488,7 @@ def walletedit(request, path=None): # print(f'--- {wd["survex file"]} - {type(wd["survex file"])}') save_json(wd) - walletobject = make_wallet(wallet) + walletobject = make_wallet(wallet) # will already exist commit_json(wd) else: @@ -510,10 +511,9 @@ def walletedit(request, path=None): if request.POST['submitbutton']=="Create": w = WALLET_BLANK_JSON.copy() save_json(w) - walletobject = make_wallet(wallet) + walletobject = make_wallet(wallet) # no date set yet commit_json(w) - fresh_wallet = True - + form = FilesForm(request.POST, request.FILES) if form.is_valid(): # print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}') @@ -537,9 +537,8 @@ def walletedit(request, path=None): save_json(waldata) walletobject = make_wallet(wallet) commit_json(waldata) - fresh_wallet = True else: - print("--- Upload files form invalid") + print("--- Upload files form invalid, which is correct if just created.") # # Not a POST, so a GET starts here. And also control gets here after a POST is processed. # @@ -560,7 +559,8 @@ def walletedit(request, path=None): "(No wallet yet. It would be created if you upload a scan and then save the form with a date.)" ) else: - if fresh_wallet: + # either on GET or on dropping-through after the POST creating a new wallet object: + if Wallet.objects.filter(walletname=wallet).exists(): create = False else: create = True @@ -592,11 +592,6 @@ def walletedit(request, path=None): context = {} if waldata: # should always be true as populated by blank data if json file doesn't exist - # if not type(waldata["people"])==list: - # if waldata["people"][0] == '"': - # waldata["people"] = waldata["people"][1:-1] - # waldata["people"] = list(waldata["people"]) - if ( not waldata["date"] or not waldata["people"] @@ -618,17 +613,16 @@ def walletedit(request, path=None): 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 svxf in waldata["survex file"]: - print(f" - {svxf=}") if svxf: svx = Path(svxf) if svx.suffix.lower() != ".svx": svx = svx.with_suffix(".svx") f = Path(settings.SURVEX_DATA) / svx if f.is_file(): - path = svx.parent / svx.stem - # print(f' - {path=}') + fpath = svx.parent / svx.stem + # print(f' - {fpath=}') try: - svxfile = SurvexFile.objects.get(path=path) + svxfile = SurvexFile.objects.get(path=fpath) print(f" - {svxfile=}") if svxfile.cave: @@ -721,6 +715,9 @@ def walletedit(request, path=None): samedate = datetime.date.fromisoformat(datestr[:10]) except: samedate = None + walletobject = make_wallet(wallet) + walletobject.walletdate = samedate + walletobject.save() try: thisexpo = Expedition.objects.get(year=int(year)) @@ -755,7 +752,7 @@ def walletedit(request, path=None): caveifywallet(thiswallet) thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form # fixsurvextick(thiswallet, thiswallet.ticks) - print(thiswallet) + print(f"--- {wallet} {thiswallet} walletdate={thiswallet.walletdate} immediately before form render") except: thiswallet = None context = { diff --git a/templates/walletform.html b/templates/walletform.html index c605a2f..871a895 100644 --- a/templates/walletform.html +++ b/templates/walletform.html @@ -68,7 +68,6 @@ {{ f}}
{% empty %}

<No files in this wallet. > -
Sub-folders here are not supported by troggle in 2022. {% endfor %}