From 2ee63a98044718a7f366aee03cac206b720ef5a8 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Sun, 30 Apr 2023 21:42:03 +0100 Subject: [PATCH] If a cave is made with no entrances, redirect to a new entrance form for the cave --- core/views/caves.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/views/caves.py b/core/views/caves.py index f83ed1c..2fad12c 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -6,7 +6,7 @@ from pathlib import Path from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect from django.shortcuts import render -from django.urls import NoReverseMatch +from django.urls import NoReverseMatch, reverse import troggle.settings as settings from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm @@ -373,8 +373,10 @@ def edit_cave(request, path="", slug=None): except subprocess.SubprocessError: message = f"CANNOT git on server for this file {cave.filename}. Edits may not be committed.\nAsk a nerd to fix this." return render(request, "errors/generic.html", {"message": message}) - - return HttpResponseRedirect("/" + cave.url) + if cave.entrances().count() > 0: + return HttpResponseRedirect("/" + cave.url) + else: + return HttpResponseRedirect(reverse("newentrance", args = [cave.url_parent(), cave.slug()])) else: if slug is not None: