2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

redirect to edit page

This commit is contained in:
Philip Sargent 2024-07-23 16:38:24 +02:00
parent 219637e215
commit f590d0c12c

View File

@ -4,6 +4,7 @@ from pathlib import Path
from django import forms from django import forms
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
import settings import settings
@ -337,10 +338,13 @@ def logbookedit(request, year=None, slug=None):
print(f"! Unrecognised author: {author}") print(f"! Unrecognised author: {author}")
# if somehow we get a slug set to just '2024', not eg '2020-08-10b' # if somehow we get a slug set to just '2024', not eg '2020-08-10b'
# because the URL of the page is /logbookedit/2022 for a new entry
# This is a hack, why can we not reproduce this bug on the dev system? # This is a hack, why can we not reproduce this bug on the dev system?
if len(slug) < 7: if slug not in locals():
slug = "" slug = ""
if len(prev_slug) < 7: if len(slug) < 11:
slug = ""
if len(prev_slug) < 11:
prev_slug = "" prev_slug = ""
if not prev_slug and not slug: if not prev_slug and not slug:
@ -464,23 +468,26 @@ def logbookedit(request, year=None, slug=None):
# This does not change the URL in the browser, so despite a new slug being created, # This does not change the URL in the browser, so despite a new slug being created,
# the next time this code is run it thinks a new slug needs to be created. So we should # the next time this code is run it thinks a new slug needs to be created. So we should
# actually redirect to a new URL (an edit not a create) not simply return a render object. # actually redirect to a new URL (an edit not a create) not simply return a render object.
return render( # logbookedit/2022-08-21a
request, return HttpResponseRedirect(f'/logbookedit/{slug}')
"logbookform.html",
{ # return render(
"form": form, # request,
"year": year, # "logbookform.html",
"date": date, "dateflag": dateflag, # {
"author": author, "authorflag": authorflag, # "form": form,
"others": others, # "year": year,
"place": place, # "date": date, "dateflag": dateflag,
"title": title, # "author": author, "authorflag": authorflag,
"tu": tu, # "others": others,
"entry": entry, # "place": place,
"output": output, # "title": title,
"slug": slug, # "tu": tu,
}, # "entry": entry,
) # "output": output,
# "slug": slug,
# },
# )
# GET here # GET here
else: else:
form = LogbookEditForm() form = LogbookEditForm()