summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-07-23 15:52:04 +0200
committerPhilip Sargent <philip.sargent@gmail.com>2024-07-23 15:52:04 +0200
commitca103fde229f31a95ebbdd5b65283f1878cc4417 (patch)
treeea676266b4ed871c6c77260dde88fdad89dac0e7 /core/views/uploads.py
parenta2f4591f725026c224e11ae7f5265546bcf5bba9 (diff)
downloadtroggle-ca103fde229f31a95ebbdd5b65283f1878cc4417.tar.gz
troggle-ca103fde229f31a95ebbdd5b65283f1878cc4417.tar.bz2
troggle-ca103fde229f31a95ebbdd5b65283f1878cc4417.zip
more debug for logbook edits
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py40
1 files changed, 23 insertions, 17 deletions
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<p>\n') # replace 2 \n with <br><br>
# entry = entry.replace('\n\n','\n<br />\n<br />\n') # replace 2 \n with <br><br>
@@ -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)