2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 14:57:13 +00:00

text file editor now using validated logon properly

This commit is contained in:
2025-02-13 16:42:51 +00:00
parent 3fb99eb4be
commit a976497b3a
4 changed files with 14 additions and 7 deletions

View File

@@ -501,9 +501,6 @@ def editexpopage(request, path):
print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/(24*3600)} days") print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/(24*3600)} days")
try: try:
change_message = pageform.cleaned_data["change_message"] change_message = pageform.cleaned_data["change_message"]
# if not identified_login:
# editor = pageform.cleaned_data["who_are_you"]
# editor = git_string(editor)
write_and_commit([(filepath, result, "utf-8")], f"{change_message} - online edit of {path}", editor) write_and_commit([(filepath, result, "utf-8")], f"{change_message} - online edit of {path}", editor)
except WriteAndCommitError as e: except WriteAndCommitError as e:
return render(request, "errors/generic.html", {"message": e.message}) return render(request, "errors/generic.html", {"message": e.message})

View File

@@ -15,7 +15,8 @@ from troggle.core.utils import (
COOKIE_MAX_AGE, COOKIE_MAX_AGE,
alphabet_suffix, alphabet_suffix,
current_expo, current_expo,
get_cookie, get_editor,
is_identified_user,
git_add, git_add,
git_commit, git_commit,
git_string, git_string,
@@ -88,6 +89,7 @@ class ExpofileRenameForm(forms.Form): # not a model-form, just a form-form
class ExpotextfileForm(forms.Form): # not a model-form, just a form-form class ExpotextfileForm(forms.Form): # not a model-form, just a form-form
"""Editing .txt files on /expoweb/ which is in a git repo""" """Editing .txt files on /expoweb/ which is in a git repo"""
text = forms.CharField(strip=True, required=False) text = forms.CharField(strip=True, required=False)
identified_login = forms.BooleanField(required=False,widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # makes it readonly
who_are_you = forms.CharField( who_are_you = forms.CharField(
widget=forms.TextInput( widget=forms.TextInput(
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Wookey' or 'Animal <mta@gasthof.expo>'", attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Wookey' or 'Animal <mta@gasthof.expo>'",
@@ -103,7 +105,11 @@ def edittxtpage(request, path, filepath):
""" """
def simple_get(viewtext): def simple_get(viewtext):
print(f"simple_get {editor=}") print(f"simple_get {editor=}")
form = ExpotextfileForm(initial={"who_are_you":editor}) form = ExpotextfileForm(initial={"identified_login": identified_login, "who_are_you":editor})
if identified_login:
# disable editing the git id string as we get it from the logged-on user data
form.fields["who_are_you"].widget.attrs["readonly"]="readonly"
return render( return render(
request, request,
"textfileform.html", "textfileform.html",
@@ -131,7 +137,8 @@ def edittxtpage(request, path, filepath):
print(message) print(message)
return render(request, "errors/generic.html", {"message": message}) return render(request, "errors/generic.html", {"message": message})
editor = get_cookie(request) identified_login = is_identified_user(request.user)
editor = get_editor(request)
if request.method == "GET": if request.method == "GET":
return simple_get(originaltext) return simple_get(originaltext)

View File

@@ -1 +1 @@
<a href='{{ page_url }}'><img src='{{ thumbnail_url }}' /></a> <a href='{{ page_url }}'><img src='{{ thumbnail_url }}' /></a>&nbsp;

View File

@@ -30,7 +30,10 @@ Full path on server: {{filepath}}
<br /><br /> <br /><br />
<div> <div>
<label for="id_identified_login">Identified login:</label>
{{form.identified_login}}<br />
<label for="id_who_are_you">Who are you:</label><br /> <label for="id_who_are_you">Who are you:</label><br />
{{form.who_are_you}} {{form.who_are_you}}
</div><br /> </div><br />