2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

make default date sensible for LBEs

This commit is contained in:
Philip Sargent 2024-08-09 02:02:46 +03:00
parent 7dbaea5d24
commit 517d27458c
2 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import subprocess import subprocess
from datetime import datetime, timezone from datetime import datetime, timezone, timedelta
from pathlib import Path from pathlib import Path
from django import forms 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). 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 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. 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): def validate_year(year):
try: try:
expo = Expedition.objects.get(year=year) expo = Expedition.objects.get(year=year)
@ -261,12 +259,16 @@ def logbookedit(request, year=None, slug=None):
return year return year
def new_entry_form(): def new_entry_form():
# set the date to be "yesterday" as this will, hopefully, usually be the case
return render( return render(
request, request,
"logbookform.html", "logbookform.html",
{ {
"form": form, "form": form,
"year": year, "year": year,
"yesterday": yesterday(),
}, },
) )
def clean_tu(tu): 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 # 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. # 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 HttpResponseRedirect(f"/logbookedit/{slug}?dateflag={dateflag}&authorflag={authorflag}")
# return render( # return render(

View File

@ -32,11 +32,16 @@
<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 %}>
<span {% if yesterday%}style="color:blue"{% endif %}>
<label for="date">Date of the activity{% if dateflag %} (cannot change year on an existing entry){% endif %}</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 %}
{% if dateflag %}style="color:red"{% endif %}
{% if yesterday%}style="color:blue"{% 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"
{% if date %}value="{{date}}"{% else %}placeholder="2023-08-12"{% endif %} {% if date %}value="{{date}}"{% else %}
{% if yesterday %} value="{{yesterday}}"{% else %}
placeholder="2025-08-12"{% endif %}{% endif %}
required /> required />
</span> </span>
@ -44,6 +49,7 @@
<span {% if authorflag %}style="color:red"{% endif %}> <span {% if authorflag %}style="color:red"{% endif %}>
<label for="author">Your name (author) <a href="/aliases/{{year}}">[valid authors]</a></label> <label for="author">Your name (author) <a href="/aliases/{{year}}">[valid authors]</a></label>
<input {% if not user.username %} disabled{% endif %} <input {% if not user.username %} disabled{% endif %}
{% if authorflag %}style="color:red"{% endif %}
label = "author" name = "author" size="20" label = "author" name = "author" size="20"
title="The person writing the logbook entry" title="The person writing the logbook entry"
{% if author %}value="{{author}}"{% else %}placeholder="Animal"{% endif %} {% if author %}value="{{author}}"{% else %}placeholder="Animal"{% endif %}