summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-02-13 15:10:12 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-02-13 15:10:12 +0000
commit3fb99eb4be5f1c3199bdc2bab3c81f3195bf8710 (patch)
treef226a4dcf5a595fa846bcffab8e54c65b6881e9e /core/utils.py
parent3a3e5765f921d30a10ca3eff3db616fb4b0d58fe (diff)
downloadtroggle-3fb99eb4be5f1c3199bdc2bab3c81f3195bf8710.tar.gz
troggle-3fb99eb4be5f1c3199bdc2bab3c81f3195bf8710.tar.bz2
troggle-3fb99eb4be5f1c3199bdc2bab3c81f3195bf8710.zip
lgoing/cookie interaction betetr
Diffstat (limited to 'core/utils.py')
-rw-r--r--core/utils.py52
1 files changed, 29 insertions, 23 deletions
diff --git a/core/utils.py b/core/utils.py
index 5e03971..26be1a0 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -168,25 +168,6 @@ def current_expo():
else:
return settings.EPOCH.year # this is 1970
-def is_identified_user(user):
- if user.is_anonymous:
- return False
- if user.username in ["expo", "expoadmin"]:
- return False
- return True
-
-def get_git_string(user):
- if not is_identified_user(user):
- return None
- else:
- people = Person.objects.filter(user=user)
- if len(people) != 1:
- # someone like "fluffy-bunny" not associated with a Person
- return None
- person = people[0]
- return f"{person.fullname} <{user.email}>"
-
-
def parse_aliases(aliasfile):
"""Reads a long text string containing pairs of strings:
(alias, target)
@@ -233,14 +214,40 @@ def parse_aliases(aliasfile):
return [(None, None)], "Fail on file reading"
return aliases, report
+def get_editor(request):
+ current_user = request.user
+ if is_identified_user(current_user):
+ return get_git_string(current_user)
+ else:
+ return get_cookie(request)
+
+def is_identified_user(user):
+ if user.is_anonymous:
+ return False
+ if user.username in ["expo", "expoadmin"]:
+ return False
+ return True
+
+def get_git_string(user):
+ if not is_identified_user(user):
+ return None
+ else:
+ people = Person.objects.filter(user=user)
+ if len(people) != 1:
+ # someone like "fluffy-bunny" not associated with a Person
+ return None
+ person = people[0]
+ return f"{person.fullname} <{user.email}>"
+
def get_cookie(request):
"""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.
+ if the default value is blank, then the form validation code makes the user type something in.
+ So having a blank is best if the cookie is to be displayed as the first value seen on a form.
+ But if the cookie is to be stored, then "Unset" may be better.
"""
# NO_COOKIE_DEFAULT = 'Unset Cookie <hohlenforscher@potatohut.expo>'
# print(f"-- Getting cookie...")
- editor_id = request.COOKIES.get('editor_id', "") # if no cookie, then default string ""
+ editor_id = request.COOKIES.get('editor_id', "")
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
@@ -268,7 +275,6 @@ def git_string(author_string):
print(f"++ Not git-compatible author string '{author_string}', replacing as '{editor}'")
return editor
-
def git_add(filename, cwd, commands=[]):
"""Add a file to the list of Staged files ready for a later git commit
"""