mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 08:17:35 +00:00
make default date sensible for LBEs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import subprocess
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from django import forms
|
||||
@@ -246,13 +246,11 @@ def logbookedit(request, year=None, slug=None):
|
||||
putting the text of the form prompt in red (same as for an invalid date, which is arguably more important).
|
||||
No check is done on the other people on the trip as this is picked up anyway by parsing on import
|
||||
and we don't really care at this point.
|
||||
|
||||
If the author name is mispelled, noticed, and changed, then two logbook entries are created
|
||||
with sequential slugs ...b ...c etc. This is because we are doing validation on GET not on POST
|
||||
and we are not rewriting the URL when a slug gets set. Hmm.
|
||||
|
||||
Normal use of this form is producing duplicate logbook entries.. why ?!
|
||||
"""
|
||||
def yesterday():
|
||||
yesterday = datetime.now() - timedelta(1)
|
||||
return yesterday.strftime('%Y-%m-%d')
|
||||
|
||||
def validate_year(year):
|
||||
try:
|
||||
expo = Expedition.objects.get(year=year)
|
||||
@@ -261,12 +259,16 @@ def logbookedit(request, year=None, slug=None):
|
||||
return year
|
||||
|
||||
def new_entry_form():
|
||||
# set the date to be "yesterday" as this will, hopefully, usually be the case
|
||||
|
||||
return render(
|
||||
request,
|
||||
"logbookform.html",
|
||||
{
|
||||
"form": form,
|
||||
"year": year,
|
||||
"yesterday": yesterday(),
|
||||
|
||||
},
|
||||
)
|
||||
def clean_tu(tu):
|
||||
@@ -474,6 +476,7 @@ def logbookedit(request, year=None, slug=None):
|
||||
|
||||
# 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.
|
||||
# so we need to pass the flags explicitly int he url and then extract them from the request in the GET bit. sigh.
|
||||
return HttpResponseRedirect(f"/logbookedit/{slug}?dateflag={dateflag}&authorflag={authorflag}")
|
||||
|
||||
# return render(
|
||||
|
||||
Reference in New Issue
Block a user