From 07fc372b4175e683631ba1905526d927a066f97e Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 23 Jul 2024 11:34:12 +0200 Subject: [PATCH] belt and braces prevent bad lbe ids --- core/views/uploads.py | 5 +++-- parsers/logbooks.py | 16 ++++++++++++++-- templates/logbookform.html | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index c58bc65..0ad168c 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -306,7 +306,8 @@ def logbookedit(request, year=None, slug=None): place = request.POST["place"].strip().replace(' - ',' = ') # no hyphens ! title = request.POST["title"].strip() entry = request.POST["text"].strip() - slug = request.POST["slug"].strip() + if "slug" in request.POST: + slug = request.POST["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

\n') # replace 2 \n with

# entry = entry.replace('\n\n','\n
\n
\n') # replace 2 \n with

@@ -334,7 +335,7 @@ def logbookedit(request, year=None, slug=None): authorflag = True print(f"! Unrecognised author: {author}") - + # slug is set either because we already posted or because it was specified inthe url if not slug: # Creating a new logbook entry with all the gubbins slug = create_new_lbe_slug(date) diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 45cc00d..69a2850 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -59,8 +59,8 @@ LOGBOOK_PARSER_SETTINGS = { LOGBOOKS_DIR = "years" # subfolder of settings.EXPOWEB ENTRIES = { - "2024": 27, - "2023": 86, + "2024": 41, + "2023": 91, "2022": 94, "2019": 55, "2018": 95, @@ -299,6 +299,11 @@ def store_entry_into_database(date, place, tripcave, title, text, trippersons, a def parser_date(tripdate, year): """Interprets dates in the expo logbooks and returns a correct datetime.date object Does NOT actually check that it is a truly valid date.. + + tripdate : string + year : string + + Nasty bug if it returns just the year which leads to a logbook id '/2023' instead of '/2023-07-16b' """ dummydate = EPOCH month = 1 @@ -410,6 +415,13 @@ def parser_html(year, expedition, txt, seq=""): continue ldate = parser_date(tripdate.strip(), year) + if len(str(ldate)) < 10: + ldate = date(year, 10, 1) # 1st October + msg = f" !- Logbook. Bad parsed date '{tripdate}' setting to '{ldate}'" + print(msg) + DataIssue.objects.create(parser="logbooks", message=msg) + continue + # Now we have a date, we can reset tripid tid = reset_trip_id(ldate) diff --git a/templates/logbookform.html b/templates/logbookform.html index 399ec2d..a84f6ce 100644 --- a/templates/logbookform.html +++ b/templates/logbookform.html @@ -86,6 +86,7 @@ {% if tu %}value="{{tu}}"{% else %}placeholder="0.1" {% endif %} />

+