mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-03-31 23:24:01 +01:00
fixed entracne creation bug
This commit is contained in:
@@ -725,22 +725,27 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
which leads to a constraint uniqueness crash. FIX THIS.
|
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
|
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.
|
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}"
|
slugname = f"{slug}{letter}"
|
||||||
nents = Entrance.objects.filter(slug=slugname).count()
|
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:
|
if nents == 0:
|
||||||
# looks good, but we need to check the CaveaAndEntrance object too
|
# looks good, but we need to check the CaveaAndEntrance object too
|
||||||
e = entrance #Entrance.objects.get(slug=slugname) # does not exist yet!
|
e = entrance #Entrance.objects.get(slug=slugname) # does not exist yet!
|
||||||
e.save()
|
e.save() # unique constraint FAIL
|
||||||
gcl = GetCaveLookup()
|
|
||||||
if slug in gcl:
|
|
||||||
c = gcl[slug]
|
|
||||||
else:
|
|
||||||
c = Cave.objects.get(slug=slug)
|
|
||||||
nce = CaveAndEntrance.objects.filter(cave=c, entrance=e).count()
|
nce = CaveAndEntrance.objects.filter(cave=c, entrance=e).count()
|
||||||
if nce == 0 :
|
if nce == 0 :
|
||||||
return slugname, letter
|
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"
|
# That entrance already exists, or the CE does, OK.. do recursive call, starting at "b"
|
||||||
if letter =="":
|
if letter =="":
|
||||||
|
|||||||
Reference in New Issue
Block a user