From c4eb14148ab757645a8824e6da96024ffa3ee192 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 17 Jan 2025 18:41:54 +0000 Subject: make cookie default to empty string - form validation then works --- core/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'core/utils.py') diff --git a/core/utils.py b/core/utils.py index 50330f1..23d6a85 100644 --- a/core/utils.py +++ b/core/utils.py @@ -205,10 +205,18 @@ def parse_aliases(aliasfile): return aliases, report def get_cookie(request): - NO_COOKIE_DEFAULT = 'Unset Cookie ' + """The initial idea of having a default turned out to be a bad idea as people just ignore the field. + if the default value is blank, then the form validation code makes the user type something in, + so having a blank is best. + """ + # NO_COOKIE_DEFAULT = 'Unset Cookie ' 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 + editor_id = request.COOKIES.get('editor_id', "") # if no cookie, then default string "" + if editor_id.startswith("Unset"): + # clean out laziness in users' PCs + editor_id = "" + else: + 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 -- cgit v1.2.3