From 38130c876b86e2a014384d2d507dba77b8c84728 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 16 Mar 2025 13:15:45 +0000 Subject: attempt to reformat logbook entries.. fail. Too many side efefcts. --- core/views/logbook_edit.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'core/views/logbook_edit.py') diff --git a/core/views/logbook_edit.py b/core/views/logbook_edit.py index 198cc38..7207842 100644 --- a/core/views/logbook_edit.py +++ b/core/views/logbook_edit.py @@ -23,6 +23,7 @@ from troggle.core.utils import ( sanitize_name, unique_slug, write_and_commit, + wrap_text, ) from troggle.parsers.people import GetPersonExpeditionNameLookup, known_foreigner @@ -70,6 +71,8 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t cave = GetCaveLookup().get(place.lower()) # print(f"store_edited_entry_into_database(): {place=} {cave=}") + text = wrap_text(text) + if LogbookEntry.objects.filter(slug=slug).exists(): # oops. message = f" ! - DUPLICATE SLUG for logbook entry {date} - {slug}" @@ -152,7 +155,21 @@ def logbookedit(request, year=None, slug=None): except: year = current_expo() # creates new Expedition object if needed return year + + def reformat_for_display(entry): + # entry = entry.replace("

", "\n\n") + return entry + def reformat_entry_from_user(entry): + """Makes it easier for user to edit, but hard to make this + idempotent over re-editing, given the wrap_text() used in the writing function. + We want \n in the file as-stored so that git works nicely. + """ + entry = entry.replace('\r','') # remove HTML-standard CR inserted from form. + entry = entry.replace('\n\n','\n

\n') # replace 2 \n with

+ + return entry + def new_entry_form(): # set the date to be "yesterday" as this will, hopefully, usually be the case @@ -212,8 +229,9 @@ def logbookedit(request, year=None, slug=None): entry = request.POST["text"].strip() 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

\n') # replace 2 \n with

+ + entry = reformat_entry_from_user(entry) + tu = request.POST["tu"].strip() tu = clean_tu(tu) @@ -391,7 +409,7 @@ def logbookedit(request, year=None, slug=None): others = others + ", " + lbe.other_people lenothers = min(70,max(20, len(others))) - text = lbe.text + text = reformat_for_display(lbe.text) rows = max(5,len(text)/50) return render( request, -- cgit v1.2.3