summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/utils.py11
-rw-r--r--core/views/caves.py9
-rw-r--r--core/views/expo.py9
-rw-r--r--core/views/survex.py7
4 files changed, 17 insertions, 19 deletions
diff --git a/core/utils.py b/core/utils.py
index 904faad..5ba1b4b 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -198,6 +198,13 @@ def parse_aliases(aliasfile):
return [(None, None)], "Fail on file reading"
return aliases, report
+def get_cookie(request):
+ NO_COOKIE_DEFAULT = 'H&ouml;hlenforscher <hohlenforscher@stonebridge.expo>'
+ print(f"-- Getting cookie...")
+ editor_id = request.COOKIES.get('editor_id', NO_COOKIE_DEFAULT) # 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 to be used: {editor=}")
+ return editor
def git_string(author_string):
"""Rewrites the supplied editor string intoa git-complient author string
@@ -207,13 +214,13 @@ def git_string(author_string):
author_regex = re.compile(r'^[a-zA-Z][\w\s\_\.\-]* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-_]+\.[a-zA-Z]{2,}>$')
if author_regex.match(author_string):
- print(f"Valid git-compatible author string: '{author_string}'")
+ print(f"++ Is valid git-compatible author string: '{author_string}'")
return author_string
else:
editor = author_string.replace("@","_at_")
editor = re.sub('[^0-9a-zA-Z_\.]+', '*', editor)
editor += f" <{editor}@potatohut.expo>"
- print(f"Not git-compatible author string, replacing as '{editor}'")
+ print(f"++ Not git-compatible author string '{author_string}', replacing as '{editor}'")
return editor
diff --git a/core/views/caves.py b/core/views/caves.py
index c91db76..ba74f7b 100644
--- a/core/views/caves.py
+++ b/core/views/caves.py
@@ -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."
diff --git a/core/views/expo.py b/core/views/expo.py
index 3cba48b..848fe21 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -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"]
diff --git a/core/views/survex.py b/core/views/survex.py
index c909a40..afa6a69 100644
--- a/core/views/survex.py
+++ b/core/views/survex.py
@@ -19,7 +19,7 @@ from troggle.core.models.caves import Cave, GetCaveLookup
from troggle.core.models.logbooks import LogbookEntry
from troggle.core.models.survex import SurvexBlock, SurvexFile #, SurvexDirectory
from troggle.core.models.wallets import Wallet
-from troggle.core.utils import COOKIE_MAX_AGE, current_expo, git_string, add_commit
+from troggle.core.utils import COOKIE_MAX_AGE, current_expo, get_cookie, git_string, add_commit
from troggle.parsers.survex import parse_one_file
"""Everything that views survexfiles
@@ -313,10 +313,7 @@ def svx(request, survex_file):
nowtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
outputtype = "normal"
- 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)
form = SvxForm({"filename": survex_file, "dirname": dirname, "datetime": nowtime, "outputtype": outputtype, "who_are_you":editor})