2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 16:51:54 +00:00

date handling now working for new wallet

This commit is contained in:
Philip Sargent 2023-02-01 19:10:46 +00:00
parent 8e51f3aff8
commit 587ccff501
3 changed files with 23 additions and 25 deletions

View File

@ -13,6 +13,7 @@ from django.urls import reverse
# from troggle.core.models.survex import SurvexBlock # from troggle.core.models.survex import SurvexBlock
# from troggle.core.models.troggle import DataIssue # circular import. Hmm # from troggle.core.models.troggle import DataIssue # circular import. Hmm
YEAR_RANGE = (1975, 2050)
class Wallet(models.Model): class Wallet(models.Model):
"""We do not keep the JSON values in the database, we query them afresh each time, """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] != "#": if self.walletname[4] != "#":
return None return None
year = int(self.walletname[0:4]) year = int(self.walletname[0:4])
if year < 1975 or year > 2050: ymin, ymax = YEAR_RANGE
if year < ymin or year > ymax:
return None return None
else: else:
self.walletyear = datetime.date(year, 1, 1) self.walletyear = datetime.date(year, 1, 1)

View File

@ -18,7 +18,7 @@ from troggle.core.models.caves import Cave
from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole
from troggle.core.models.troggle import DataIssue, Expedition 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.caves import getCave
from troggle.core.views.scans import caveifywallet, oldwallet from troggle.core.views.scans import caveifywallet, oldwallet
@ -125,7 +125,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
or waldata["people"] == [""] or waldata["people"] == [""]
): ):
complaints.append( 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 ?? # 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): if not re.match("(19|20)\d\d[:#]\d\d\d?", wpath):
return (None, get_next_empty() ) return (None, get_next_empty() )
if int(year) < 1977: ymin, ymax = YEAR_RANGE
year = "1977" if int(year) < ymin:
if int(year) > 2050: year = str(ymin+2)
if int(year) > ymax:
return (None, get_next_empty() ) return (None, get_next_empty() )
wallet = f"{year}:{wnumber:02d}" wallet = f"{year}:{wnumber:02d}"
return (None, wallet) return (None, wallet)
def create_nav_links(wallet): def create_nav_links(wallet):
print(f" --- {wallet}") print(f"--- {wallet} now current")
y = wallet[:4] y = wallet[:4]
n = wallet[5:] n = wallet[5:]
nexty = f"{int(y)+1}" nexty = f"{int(y)+1}"
@ -487,7 +488,7 @@ def walletedit(request, path=None):
# print(f'--- {wd["survex file"]} - {type(wd["survex file"])}') # print(f'--- {wd["survex file"]} - {type(wd["survex file"])}')
save_json(wd) save_json(wd)
walletobject = make_wallet(wallet) walletobject = make_wallet(wallet) # will already exist
commit_json(wd) commit_json(wd)
else: else:
@ -510,9 +511,8 @@ def walletedit(request, path=None):
if request.POST['submitbutton']=="Create": if request.POST['submitbutton']=="Create":
w = WALLET_BLANK_JSON.copy() w = WALLET_BLANK_JSON.copy()
save_json(w) save_json(w)
walletobject = make_wallet(wallet) walletobject = make_wallet(wallet) # no date set yet
commit_json(w) commit_json(w)
fresh_wallet = True
form = FilesForm(request.POST, request.FILES) form = FilesForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
@ -537,9 +537,8 @@ def walletedit(request, path=None):
save_json(waldata) save_json(waldata)
walletobject = make_wallet(wallet) walletobject = make_wallet(wallet)
commit_json(waldata) commit_json(waldata)
fresh_wallet = True
else: 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. # 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.)" "(No wallet yet. It would be created if you upload a scan and then save the form with a date.)"
) )
else: 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 create = False
else: else:
create = True create = True
@ -592,11 +592,6 @@ def walletedit(request, path=None):
context = {} context = {}
if waldata: # should always be true as populated by blank data if json file doesn't exist 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 ( if (
not waldata["date"] not waldata["date"]
or not waldata["people"] 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 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"]] waldata["survex file"] = [waldata["survex file"]]
for svxf in waldata["survex file"]: for svxf in waldata["survex file"]:
print(f" - {svxf=}")
if svxf: if svxf:
svx = Path(svxf) svx = Path(svxf)
if svx.suffix.lower() != ".svx": if svx.suffix.lower() != ".svx":
svx = svx.with_suffix(".svx") svx = svx.with_suffix(".svx")
f = Path(settings.SURVEX_DATA) / svx f = Path(settings.SURVEX_DATA) / svx
if f.is_file(): if f.is_file():
path = svx.parent / svx.stem fpath = svx.parent / svx.stem
# print(f' - {path=}') # print(f' - {fpath=}')
try: try:
svxfile = SurvexFile.objects.get(path=path) svxfile = SurvexFile.objects.get(path=fpath)
print(f" - {svxfile=}") print(f" - {svxfile=}")
if svxfile.cave: if svxfile.cave:
@ -721,6 +715,9 @@ def walletedit(request, path=None):
samedate = datetime.date.fromisoformat(datestr[:10]) samedate = datetime.date.fromisoformat(datestr[:10])
except: except:
samedate = None samedate = None
walletobject = make_wallet(wallet)
walletobject.walletdate = samedate
walletobject.save()
try: try:
thisexpo = Expedition.objects.get(year=int(year)) thisexpo = Expedition.objects.get(year=int(year))
@ -755,7 +752,7 @@ def walletedit(request, path=None):
caveifywallet(thiswallet) caveifywallet(thiswallet)
thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form thiswallet.ticks = thiswallet.get_ticks() # the complaints in colour form
# fixsurvextick(thiswallet, thiswallet.ticks) # fixsurvextick(thiswallet, thiswallet.ticks)
print(thiswallet) print(f"--- {wallet} {thiswallet} walletdate={thiswallet.walletdate} immediately before form render")
except: except:
thiswallet = None thiswallet = None
context = { context = {

View File

@ -68,7 +68,6 @@
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{f}}">{{ f}}</a><br /> <a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{f}}">{{ f}}</a><br />
{% empty %} {% empty %}
<p>&lt;No files in this wallet. &gt; <p>&lt;No files in this wallet. &gt;
<br>Sub-folders here are not supported by troggle in 2022.
{% endfor %} {% endfor %}
<ul> <ul>