summaryrefslogtreecommitdiffstats
path: root/core/views/expo.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-01-26 19:04:56 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-01-26 19:04:56 +0000
commitce508b0eb28551efbb9d7aaf18f1e76994e7c38b (patch)
tree7d9086dcc8b4d73959018d6f7ccd5e13b858c37a /core/views/expo.py
parent7fab42fa9e4067fdd99eca81d736d37c50f27291 (diff)
downloadtroggle-ce508b0eb28551efbb9d7aaf18f1e76994e7c38b.tar.gz
troggle-ce508b0eb28551efbb9d7aaf18f1e76994e7c38b.tar.bz2
troggle-ce508b0eb28551efbb9d7aaf18f1e76994e7c38b.zip
Use logon not cookie when editing pages
Diffstat (limited to 'core/views/expo.py')
-rw-r--r--core/views/expo.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/core/views/expo.py b/core/views/expo.py
index 89215a4..63f1d33 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -19,7 +19,9 @@ from troggle.core.utils import (
current_expo,
get_cookie,
git_string,
+ get_git_string,
write_and_commit,
+ is_identified_user
)
from troggle.core.views.editor_helpers import HTMLarea
from troggle.core.views.uploads import edittxtpage
@@ -455,15 +457,17 @@ def editexpopage(request, path):
print("### File not found ### ", filepath)
filefound = False
- editor = get_cookie(request)
-
+ current_user = request.user
+ if identified_login := is_identified_user(current_user):
+ editor = get_git_string(current_user)
+ else:
+ 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
if pageform.is_valid(): # Form valid therefore write file
editor = pageform.cleaned_data["who_are_you"]
editor = git_string(editor)
- # print("### \n", str(pageform)[0:300])
- # print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken'])
if filefound:
headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
if headmatch:
@@ -490,7 +494,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/3600} hours")
+ print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/(24*3600)} days")
try:
change_message = pageform.cleaned_data["change_message"]
editor = pageform.cleaned_data["who_are_you"]
@@ -507,9 +511,9 @@ def editexpopage(request, path):
(title,) = m.groups()
else:
title = ""
- pageform = ExpoPageForm(initial={"who_are_you":editor, "html": body, "title": title})
+ pageform = ExpoPageForm(initial={"identified_login": identified_login, "who_are_you":editor, "html": body, "title": title})
else:
- pageform = ExpoPageForm(initial={"who_are_you":editor})
+ pageform = ExpoPageForm(initial={"identified_login": identified_login, "who_are_you":editor})
return render(
@@ -540,6 +544,8 @@ class ExpoPageForm(forms.Form):
"style": "vertical-align: text-top;"}
)
)
+ identified_login = forms.BooleanField(widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # make it readonly
+
who_are_you = forms.CharField(
widget=forms.Textarea(
attrs={"cols": 90, "rows": 1, "placeholder": "You have edited this page, who are you ? e.g. 'Animal <mta@gasthof.expo>'",