summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-08-09 00:58:40 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2024-08-09 00:58:40 +0300
commit7dbaea5d24feff4cfa166bbea0a15acb27bb19f9 (patch)
tree1aff7f20f342d8dd1d4788c28fc4ac86f18f1cf4 /core
parent859d9a5b22c1d5c5aedc86dad9067fee6d355b8d (diff)
downloadtroggle-7dbaea5d24feff4cfa166bbea0a15acb27bb19f9.tar.gz
troggle-7dbaea5d24feff4cfa166bbea0a15acb27bb19f9.tar.bz2
troggle-7dbaea5d24feff4cfa166bbea0a15acb27bb19f9.zip
forbid changing year when editing existing logbook entry
Diffstat (limited to 'core')
-rw-r--r--core/views/uploads.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index ae8e69a..0dcc7f3 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -311,17 +311,19 @@ def logbookedit(request, year=None, slug=None):
if "prev_slug" in request.POST:
prev_slug = request.POST["prev_slug"].strip() # if we are re-editing the same entry again
entry = entry.replace('\r','') # remove HTML-standard CR inserted from form.
- entry = entry.replace('\n\n','\n<p>\n') # replace 2 \n with <br><br>
- # entry = entry.replace('\n\n','\n<br />\n<br />\n') # replace 2 \n with <br><br>
- # entry = entry.replace('<p>','<br />\n<br') # replace <p> tag with <br><br>
- # entry = entry.replace('<p ','<br />\n<br') # replace <p> tag with attributes with <br><br>
- # entry = entry.replace('<br>','<br />') # clean up previous hack
+ entry = entry.replace('\n\n','\n<p>\n') # replace 2 \n with <p>
tu = request.POST["tu"].strip()
tu = clean_tu(tu)
try:
odate = datetime.strptime(date.replace(".", "-"), "%Y-%m-%d").date()
- dateflag = False
+ print(f"{odate.year=}")
+ if str(odate.year) == year:
+ dateflag = False
+ else:
+ print(f"Trying to change the year ! No!! {odate.year=}")
+ odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
+ dateflag = True
except:
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
print(f"! Invalid date string {date}, setting to {odate}")
@@ -469,7 +471,10 @@ def logbookedit(request, year=None, slug=None):
# the next time this code is run it thinks a new slug needs to be created. So we should
# actually redirect to a new URL (an edit not a create) not simply return a render object.
# logbookedit/2022-08-21a
- return HttpResponseRedirect(f'/logbookedit/{slug}')
+
+ # HOWEVER by doing a redirect rather than returning a rendered page, we lose all the
+ # error settings e.g dateflag and authroflag so the user gets no feedback about bad data entered.
+ return HttpResponseRedirect(f"/logbookedit/{slug}?dateflag={dateflag}&authorflag={authorflag}")
# return render(
# request,
@@ -492,6 +497,16 @@ def logbookedit(request, year=None, slug=None):
else:
form = LogbookEditForm()
year = validate_year(year)
+
+ if request.GET.get('dateflag', 'False') == "True":
+ dateflag = True
+ else:
+ dateflag = False
+
+ if request.GET.get('authorflag', 'False') == "True":
+ authorflag = True
+ else:
+ authorflag = False
if not slug: # no slug or bad slug for an lbe which does not exist
return new_entry_form()
@@ -516,11 +531,9 @@ def logbookedit(request, year=None, slug=None):
# people.append(p.personexpedition.person.fullname)
people.append(p.nickname_used)
others =', '.join(people)
- print(f"{others=}")
if lbe.other_people:
others = others + ", " + lbe.other_people
lenothers = min(70,max(20, len(others)))
- print(f"{others=}")
text = lbe.text
rows = max(5,len(text)/50)
@@ -530,8 +543,8 @@ def logbookedit(request, year=None, slug=None):
{
"form": form,
"year": year,
- "date": lbe.date.isoformat(),
- "author": author,
+ "date": lbe.date.isoformat(), "dateflag": dateflag,
+ "author": author, "authorflag": authorflag,
"others": others,
"lenothers": lenothers,
"place": lbe.place,