mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-01-20 20:04:51 +00: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.
|
||||
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 =="":
|
||||
|
||||
Reference in New Issue
Block a user