From b6ffcb63bf186e154dbf25d9dce8754c031d7a82 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 3 Jul 2024 12:34:21 +0300 Subject: [PATCH] error handling for txt editor --- core/views/uploads.py | 26 +++++++++++++++++++++++++- templates/textfileform.html | 7 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index 2ee01f3..6ebec8c 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -155,6 +155,7 @@ class LogbookEditForm(forms.Form): # not a model-form, just a form-form def edittxtpage(request, path, filepath): """Editing a .txt file on expoweb/ """ + message="" def simple_get(): form = ExpotextfileForm() return render( @@ -163,6 +164,7 @@ def edittxtpage(request, path, filepath): { "form": form, "path": path, + "message": message, "filepath": filepath, "text": text, }, @@ -183,7 +185,29 @@ def edittxtpage(request, path, filepath): return simple_get() elif request.method == "POST": - pass + form = ExpotextfileForm(request.POST) + if not form.is_valid(): + message = f'Invalid form response for text file editing "{request.POST}"' + print(message) + return render(request, "errors/generic.html", {"message": message}) + else: + for i in request.POST: + print(":: ",i, " => ", request.POST[i]) + + print("POST") + if "Cancel" in request.POST: + print("cancel") + return simple_get() + if "Save" in request.POST: + print("submitted for saving..") + message="submitted for saving.. not implemented yet.." + + # INSERT FILE SAVING AND git committing on server + return simple_get() + # mistake, abort + message="Something went wrong" + return simple_get() + @login_required_if_public def logbookedit(request, year=None, slug=None): diff --git a/templates/textfileform.html b/templates/textfileform.html index 27fa0d3..2110598 100644 --- a/templates/textfileform.html +++ b/templates/textfileform.html @@ -13,6 +13,9 @@
File: {{path}}
Full path on server: {{filepath}} +{% if message %} +

{{message}}

+{% endif %}
{% csrf_token %} @@ -30,6 +33,10 @@ Full path on server: {{filepath}} title="Saves the file in UTF-8 characterset" value = "Save" > Save the file +