mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 05:07:06 +00:00
attempt to reformat logbook entries.. fail. Too many side efefcts.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user