2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-30 07:29:50 +01: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

@@ -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