2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 05:17:19 +00:00

cave edit working with cookies

This commit is contained in:
2024-12-28 22:43:21 +00:00
parent ecd187e88e
commit e7444d20a4
4 changed files with 17 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ from troggle.core.forms import CaveForm, EntranceForm, EntranceLetterForm # Cav
from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup, get_cave_leniently
from troggle.core.models.logbooks import QM
from troggle.core.models.wallets import Wallet
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, current_expo, git_string, write_and_commit
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, current_expo, get_cookie, git_string, write_and_commit
from troggle.core.views import expo
from troggle.parsers.caves import read_cave, read_entrance
from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS
@@ -477,10 +477,7 @@ def edit_cave(request, path="", slug=None):
if not (cave:= get_cave_from_slug(slug)): # walrus operator
return render(request, "errors/badslug.html", {"badslug": f"for cave {caveslug} - from edit_cave()"})
print(f"Reading cookie...")
editor_id = request.COOKIES.get('editor_id', 'H&ouml;hlenforscher <hohlenforscher@stonebridge.expo>') # if no cookie, then default string
editor = git_string(editor_id) # belt and braces, should have been validity checked on saving already
print(f"Cookie read: {editor_id=} reformatted as: {editor=}")
editor = get_cookie(request)
if request.POST:
form = CaveForm(request.POST, instance=cave)
@@ -511,7 +508,7 @@ def edit_cave(request, path="", slug=None):
try:
cave_file = cave.file_output()
write_and_commit([cave_file], f"Online edit of cave {cave}")
write_and_commit([cave_file], f"Online edit of cave {cave}", editor)
# leave other exceptions unhandled so that they bubble up to user interface
except PermissionError:
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {cave.filename}. Ask a nerd to fix this."