mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
forbid changing year when editing existing logbook entry
This commit is contained in:
parent
859d9a5b22
commit
7dbaea5d24
@ -311,17 +311,19 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
if "prev_slug" in request.POST:
|
if "prev_slug" in request.POST:
|
||||||
prev_slug = request.POST["prev_slug"].strip() # if we are re-editing the same entry again
|
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('\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<p>\n') # replace 2 \n with <p>
|
||||||
# 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
|
|
||||||
tu = request.POST["tu"].strip()
|
tu = request.POST["tu"].strip()
|
||||||
tu = clean_tu(tu)
|
tu = clean_tu(tu)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
odate = datetime.strptime(date.replace(".", "-"), "%Y-%m-%d").date()
|
odate = datetime.strptime(date.replace(".", "-"), "%Y-%m-%d").date()
|
||||||
|
print(f"{odate.year=}")
|
||||||
|
if str(odate.year) == year:
|
||||||
dateflag = False
|
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:
|
except:
|
||||||
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
|
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
|
||||||
print(f"! Invalid date string {date}, setting to {odate}")
|
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
|
# 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.
|
# actually redirect to a new URL (an edit not a create) not simply return a render object.
|
||||||
# logbookedit/2022-08-21a
|
# 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(
|
# return render(
|
||||||
# request,
|
# request,
|
||||||
@ -493,6 +498,16 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
form = LogbookEditForm()
|
form = LogbookEditForm()
|
||||||
year = validate_year(year)
|
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
|
if not slug: # no slug or bad slug for an lbe which does not exist
|
||||||
return new_entry_form()
|
return new_entry_form()
|
||||||
else:
|
else:
|
||||||
@ -516,11 +531,9 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
# people.append(p.personexpedition.person.fullname)
|
# people.append(p.personexpedition.person.fullname)
|
||||||
people.append(p.nickname_used)
|
people.append(p.nickname_used)
|
||||||
others =', '.join(people)
|
others =', '.join(people)
|
||||||
print(f"{others=}")
|
|
||||||
if lbe.other_people:
|
if lbe.other_people:
|
||||||
others = others + ", " + lbe.other_people
|
others = others + ", " + lbe.other_people
|
||||||
lenothers = min(70,max(20, len(others)))
|
lenothers = min(70,max(20, len(others)))
|
||||||
print(f"{others=}")
|
|
||||||
|
|
||||||
text = lbe.text
|
text = lbe.text
|
||||||
rows = max(5,len(text)/50)
|
rows = max(5,len(text)/50)
|
||||||
@ -530,8 +543,8 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
{
|
{
|
||||||
"form": form,
|
"form": form,
|
||||||
"year": year,
|
"year": year,
|
||||||
"date": lbe.date.isoformat(),
|
"date": lbe.date.isoformat(), "dateflag": dateflag,
|
||||||
"author": author,
|
"author": author, "authorflag": authorflag,
|
||||||
"others": others,
|
"others": others,
|
||||||
"lenothers": lenothers,
|
"lenothers": lenothers,
|
||||||
"place": lbe.place,
|
"place": lbe.place,
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<input name="prev_slug" id="prev_slug" value="{{slug}}" type=hidden>
|
<input name="prev_slug" id="prev_slug" value="{{slug}}" type=hidden>
|
||||||
|
|
||||||
<span {% if dateflag %}style="color:red"{% endif %}>
|
<span {% if dateflag %}style="color:red"{% endif %}>
|
||||||
<label for="date">Date of the activity</label>
|
<label for="date">Date of the activity{% if dateflag %} (cannot change year on an existing entry){% endif %}</label>
|
||||||
<input {% if not user.username %} disabled{% endif %}
|
<input {% if not user.username %} disabled{% endif %}
|
||||||
label = "Date" name = "date" size="12"
|
label = "Date" name = "date" size="12"
|
||||||
title="Date of the activity, a single day, in ISO format: 2020-08-17"
|
title="Date of the activity, a single day, in ISO format: 2020-08-17"
|
||||||
|
Loading…
Reference in New Issue
Block a user