diff options
Diffstat (limited to 'core/views/caves.py')
-rw-r--r-- | core/views/caves.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/core/views/caves.py b/core/views/caves.py index 5ac3725..3884a1a 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -561,46 +561,52 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): print(f"- POST {caveslug=} {entslug=} {entranceletter=} {path=}") if entslug is None: # we are creating a new entrance + entrance = entform.save(commit=False) + # entrance = ce.entrance # the one we created earlier? + if entranceletter: slugname, letter = check_new_slugname_ok(cave.slug(), entranceletter) else: slugname, letter = check_new_slugname_ok(cave.slug(), "") ce.entranceletter = letter - entrance = ce.entrance # the one we created earlier entrance.slug = slugname entrance.cached_primary_slug = slugname entrance.filename = slugname + ".html" else: + # an existing entrance ? entrance.slug = entslug entrance.cached_primary_slug = entslug entrance.filename = entslug + ".html" try: entrance.save() - except: + print(f"- post {entrance.slug=} {entrance.tag_station=} {entrance.other_station=}") + except Exception as e: # fails with uniqueness constraint failure. Which is on CaveAndEntrance, not just on entrance, # which is confusing to a user who is just editing an Entrance. # Can happen when user specifies an existing letter! (or none, when they should set one) print(f"SAVE EXCEPTION FAIL {entrance=}") - print(f"CAVE {cave}") + print(f"CAVE {cave}\n{e}") for ce in cave.entrances(): print(f"CAVE:{ce.cave} - ENT:{ce.entrance} - LETTER:'{ce.entranceletter}'") raise ce.entrance = entrance - # try not to do this: + # try not to invoke this: # UNIQUE constraint failed: core_caveandentrance.cave_id, core_caveandentrance.entranceletter ce.save() entrance_file = entrance.file_output() cave_file = cave.file_output() + print(f"- POST WRITE letter: '{ce}' {entrance=}") - if write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}"): + try: + write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}") return HttpResponseRedirect("/" + cave.url) - else: + except Exception as e: efilepath, econtent, eencoding = entrance_file cfilepath, ccontent, cencoding = cave_file - message = f"- FAIL write_and_commit \n entr:'{efilepath}'\n cave:'{cfilepath}'" + message = f"- FAIL write_and_commit \n entr:'{efilepath}'\n cave:'{cfilepath}'\n\n{e}" print(message) return render(request, "errors/generic.html", {"message": message}) @@ -611,8 +617,12 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): if entrance: # re-read entrance data from file. filename = str(entrance.slug +".html") - ent = read_entrance(filename, ent=entrance) - print(f"ENTRANCE from file: entranceletter = '{ce.entranceletter}'") + try: + ent = read_entrance(filename, ent=entrance) + print(f"ENTRANCE from file: entranceletter = '{ce.entranceletter}'") + except: + # ent only in db not on file. Interesting, let's run with it using whatever we have in the db + print(f"ENTRANCE NOT read from file: entranceletter = '{ce.entranceletter}'") entform = EntranceForm(instance=entrance) if entslug is None: |