From ca103fde229f31a95ebbdd5b65283f1878cc4417 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 23 Jul 2024 15:52:04 +0200 Subject: [PATCH] more debug for logbook edits --- core/views/logbooks.py | 2 +- core/views/uploads.py | 40 ++++++++++++++++++++++---------------- templates/logbookform.html | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 5d9dca2..5f560e8 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -230,7 +230,7 @@ def logentrydelete(request, year): print(f" - '{i}' {request.POST[i]}") eslug = request.POST["entry_slug"] entry = LogbookEntry.objects.get(slug=eslug) - # OK we delete it formt he db and then re-save logbook.html file + # OK we delete it from the db and then re-save logbook.html file # to ensure that the permanent record also has the entry deleted. entry.delete() diff --git a/core/views/uploads.py b/core/views/uploads.py index 0ad168c..86b5f6c 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -291,6 +291,7 @@ def logbookedit(request, year=None, slug=None): author = "" if request.method == "POST": + prev_slug = "" # None value pending overwrite from submitted form form = LogbookEditForm(request.POST) if not form.is_valid(): message = f'Invalid form response for logbook entry creating "{request.POST}"' @@ -306,8 +307,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() - if "slug" in request.POST: - slug = request.POST["slug"].strip() # if we are re-editing the same entry again + 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 = entry.replace('\n\n','\n
\n
\n') # replace 2 \n with

@@ -335,15 +336,20 @@ 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: + if not prev_slug and not slug: # Creating a new logbook entry with all the gubbins slug = create_new_lbe_slug(date) - else: - # OK we could patch the object in place, but if the people on the trip have changed this - # would get very messy. So we delete it and recreate it and all its links - print(f"- Deleting the LogBookEntry {slug}") - LogbookEntry.objects.filter(slug=slug).delete() + + if prev_slug and not slug: + # if this was a previous post, then prev_slug will have been set on the form + # we are editing a previous thing, so we don't create a new lbe + slug = prev_slug + + # OK we could patch the object in place, but if the people on the trip have changed this + # would get very messy. So we delete it, and thus all the dependent objects, + # and recreate it and all its links. It might not exist though. + print(f"- Deleting the LogBookEntry {slug}") + LogbookEntry.objects.filter(slug=slug).delete() # works even if it does not exist print(f"- Creating the LogBookEntry {slug}") year = slug[0:4] @@ -351,13 +357,13 @@ def logbookedit(request, year=None, slug=None): expedition = Expedition.objects.get(year=year) except Expedition.DoesNotExist: message = f'''! - This expo "{year}" not created yet - It needs to be created before you can save a logbook entry. - See /handbook/computing/newyear.html - - WHAT TO DO NOW: - 1. Press the Back button on your proswer to return to the screen where you typed up the entry, - 2. Copy the text of what you wrote into a new text file, - 3. Direct a nerd to fix this. It should take only a couple of minutes.''' + It needs to be created before you can save a logbook entry. + See /handbook/computing/newyear.html + + WHAT TO DO NOW: + 1. Press the Back button on your proswer to return to the screen where you typed up the entry, + 2. Copy the text of what you wrote into a new text file, + 3. Direct a nerd to fix this. It should take only a couple of minutes.''' print(message) return render(request, "errors/generic.html", {"message": message}) store_edited_entry_into_database(date, place, title, entry, others, author, tu, slug) @@ -440,7 +446,7 @@ def logbookedit(request, year=None, slug=None): + str(lbe_commit.returncode) ) message = ( - f"! - FORM Logbook Edit -Error code with git on server for {filename}. {slug} edits saved, added to git, but NOT committed.\n" + f"! - FORM Logbook Edit -Error code '{lbe_commit.returncode}' with git on server for {filename}. {slug} edits saved, added to git, but NOT committed.\n" + msgdata ) print(message) diff --git a/templates/logbookform.html b/templates/logbookform.html index a84f6ce..ebc5111 100644 --- a/templates/logbookform.html +++ b/templates/logbookform.html @@ -29,7 +29,7 @@

{% csrf_token %}
- +