mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 00:31:55 +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:
|
||||
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,
|
||||
|
@ -32,7 +32,7 @@
|
||||
<input name="prev_slug" id="prev_slug" value="{{slug}}" type=hidden>
|
||||
|
||||
<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 %}
|
||||
label = "Date" name = "date" size="12"
|
||||
title="Date of the activity, a single day, in ISO format: 2020-08-17"
|
||||
|
Loading…
Reference in New Issue
Block a user