diff --git a/core/views/caves.py b/core/views/caves.py index a0bc2ea..ad77d65 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -725,22 +725,27 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): which leads to a constraint uniqueness crash. FIX THIS. The letter may be set to an existing letter, OR it may be unset, but there may be an existing unlettered single entrance. Both of these will crash unless fixed. + + Entrance has a field '.slug' + Cave has a function '.slug()' + + NOT as robust as it should be ! """ slugname = f"{slug}{letter}" nents = Entrance.objects.filter(slug=slugname).count() - print(f"check_new_slugname_ok() {slugname=} {letter=} => {nents}") + if not (c:= get_cave_from_slug(caveslug)): # walrus operator + return None + print(f"check_new_slugname_ok() {slugname=} {letter=} => {nents}=(number of entrances) ") if nents == 0: # looks good, but we need to check the CaveaAndEntrance object too e = entrance #Entrance.objects.get(slug=slugname) # does not exist yet! - e.save() - gcl = GetCaveLookup() - if slug in gcl: - c = gcl[slug] - else: - c = Cave.objects.get(slug=slug) + e.save() # unique constraint FAIL nce = CaveAndEntrance.objects.filter(cave=c, entrance=e).count() if nce == 0 : return slugname, letter + else: + return False # ouch, what should happen here + # That entrance already exists, or the CE does, OK.. do recursive call, starting at "b" if letter =="":