diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-12-29 03:42:58 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-12-29 03:42:58 +0000 |
commit | 6d2484376a5816387fedfb03eb83c42bcb81d6a1 (patch) | |
tree | 827fc860739fe0cdcea4904bb07513b81486c752 /core/views/uploads.py | |
parent | 13c5d14a9fb102d1f5ea78fcd58b6e2a30fe81b7 (diff) | |
download | troggle-6d2484376a5816387fedfb03eb83c42bcb81d6a1.tar.gz troggle-6d2484376a5816387fedfb03eb83c42bcb81d6a1.tar.bz2 troggle-6d2484376a5816387fedfb03eb83c42bcb81d6a1.zip |
refactor & git author work
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r-- | core/views/uploads.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py index c7b7e74..f4e2278 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -12,7 +12,7 @@ from troggle.core.models.caves import GetCaveLookup from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry, writelogbook from troggle.core.models.survex import DrawingFile from troggle.core.models.troggle import DataIssue, Expedition, PersonExpedition -from troggle.core.utils import alphabet_suffix, current_expo, sanitize_name, unique_slug, write_and_commit +from troggle.core.utils import COOKIE_MAX_AGE, alphabet_suffix, current_expo, get_cookie, git_string, sanitize_name, unique_slug, write_and_commit from troggle.parsers.people import GetPersonExpeditionNameLookup, known_foreigner # from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time* @@ -150,6 +150,12 @@ class ExpofileRenameForm(forms.Form): # not a model-form, just a form-form class ExpotextfileForm(forms.Form): # not a model-form, just a form-form text = forms.CharField(strip=True, required=False) + who_are_you = forms.CharField( + widget=forms.TextInput( + attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Wookey' or 'Animal <mta@gasthof.expo>'", + "style": "vertical-align: text-top;"} + ) + ) class LogbookEditForm(forms.Form): # not a model-form, just a form-form author = forms.CharField(strip=True, required=False) @@ -160,7 +166,8 @@ def edittxtpage(request, path, filepath): Yes this is a security hazard as arbitrary text can be uploaded and it is not enclosed in any HTML furniture. """ def simple_get(viewtext): - form = ExpotextfileForm() + print(f"simple_get {editor=}") + form = ExpotextfileForm(initial={"who_are_you":editor}) return render( request, "textfileform.html", @@ -188,6 +195,7 @@ def edittxtpage(request, path, filepath): print(message) return render(request, "errors/generic.html", {"message": message}) + editor = get_cookie(request) if request.method == "GET": return simple_get(originaltext) @@ -198,6 +206,9 @@ def edittxtpage(request, path, filepath): print(message) return render(request, "errors/generic.html", {"message": message}) else: + editor = form.cleaned_data["who_are_you"] + editor = git_string(editor) + # for i in request.POST: # print(":: ",i, " => ", request.POST[i]) newtext = request.POST["text"] @@ -215,7 +226,7 @@ def edittxtpage(request, path, filepath): if newtext != originaltext: # Check if content has changed at all print("text changed.. saving and committing") try: - write_and_commit([(filepath, newtext, "utf-8")], f"Online edit of {path}") + write_and_commit([(filepath, newtext, "utf-8")], f"Online edit of {path}", editor) except WriteAndCommitError as e: return render(request, "errors/generic.html", {"message": e.message}) @@ -228,7 +239,9 @@ def edittxtpage(request, path, filepath): return render(request, "errors/generic.html", {"message": e.message}) savepath = "/" + path print(f"redirect {savepath}") - return redirect(savepath) # Redirect after POST + response = redirect(savepath) # Redirect after POST + response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds + return response else: # no changes |