2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 14:51:51 +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.core.files.storage import FileSystemStorage
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
import settings
@ -337,10 +338,13 @@ def logbookedit(request, year=None, slug=None):
print(f"! Unrecognised author: {author}")
# 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?
if len(slug) < 7:
if slug not in locals():
slug = ""
if len(prev_slug) < 7:
if len(slug) < 11:
slug = ""
if len(prev_slug) < 11:
prev_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,
# 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.
return render(
request,
"logbookform.html",
{
"form": form,
"year": year,
"date": date, "dateflag": dateflag,
"author": author, "authorflag": authorflag,
"others": others,
"place": place,
"title": title,
"tu": tu,
"entry": entry,
"output": output,
"slug": slug,
},
)
# logbookedit/2022-08-21a
return HttpResponseRedirect(f'/logbookedit/{slug}')
# return render(
# request,
# "logbookform.html",
# {
# "form": form,
# "year": year,
# "date": date, "dateflag": dateflag,
# "author": author, "authorflag": authorflag,
# "others": others,
# "place": place,
# "title": title,
# "tu": tu,
# "entry": entry,
# "output": output,
# "slug": slug,
# },
# )
# GET here
else:
form = LogbookEditForm()