diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-03-16 13:15:45 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-03-16 13:15:45 +0000 |
commit | 38130c876b86e2a014384d2d507dba77b8c84728 (patch) | |
tree | b3c14d73febefec18006df9367988754ab3f3dcc /core/views | |
parent | 31c77fd89c831d4e6450d5b29755954e329d5d0f (diff) | |
download | troggle-38130c876b86e2a014384d2d507dba77b8c84728.tar.gz troggle-38130c876b86e2a014384d2d507dba77b8c84728.tar.bz2 troggle-38130c876b86e2a014384d2d507dba77b8c84728.zip |
attempt to reformat logbook entries.. fail. Too many side efefcts.
Diffstat (limited to 'core/views')
-rw-r--r-- | core/views/logbook_edit.py | 24 |
1 files changed, 21 insertions, 3 deletions
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("<p>", "\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<p>\n') # replace 2 \n with <p>
+
+ 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<p>\n') # replace 2 \n with <p>
+
+ 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,
|