2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 00:27:07 +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

@@ -14,7 +14,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
import troggle.core.views.caves
import troggle.settings as settings
from troggle.core.models.caves import Cave
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.editor_helpers import HTMLarea
from troggle.core.views.uploads import edittxtpage
@@ -451,10 +451,7 @@ def editexpopage(request, path):
print("### File not found ### ", filepath)
filefound = False
print(f"Reading cookie...")
editor_id = request.COOKIES.get('editor_id', 'speleologist') # 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.method == "POST": # If the form has been submitted...
pageform = ExpoPageForm(request.POST) # A form bound to the POST data
@@ -488,7 +485,7 @@ def editexpopage(request, path):
if not filefound or result != html: # Check if content changed at all
edit_response = HttpResponseRedirect(reverse("expopage", args=[path])) # Redirect after POST
edit_response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds
print(f"Cookie set: {editor} for {COOKIE_MAX_AGE} seconds")
print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/3600} hours")
try:
change_message = pageform.cleaned_data["change_message"]
editor = pageform.cleaned_data["who_are_you"]