From b1a5251768f05b1bcc97f287501c9a50d57e309d Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 8 Aug 2023 00:43:12 +0300 Subject: [PATCH] Format new logbook entry --- core/views/uploads.py | 61 +++++++++++++++++++++++++++++++------- templates/logbookform.html | 44 ++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 14 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index cdc633b..53c59cb 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -63,16 +63,57 @@ def logbookedit(request, year=None): author = "Zonker" if not year: year = 2023 - form = LogbookEditForm() - return render( - request, - "logbookform.html", - { - "form": form, - "year": year, - "author": author, - }, - ) + + if request.method == "POST": + form = LogbookEditForm(request.POST) + if not form.is_valid(): + message = f'Invalid form response for logbook entry creating "{request.POST}"' + print(message) + return render(request, "errors/generic.html", {"message": message}) + else: + # validation all to be done yet.. + author = request.POST["author"] + date = request.POST["date"] + others = request.POST["others"] + place = request.POST["place"] + title = request.POST["title"] + entry = request.POST["text"] + tu = request.POST["tu"] + seq = 99 + # OK this could be done by rendering a template, but for such a small bit of HTML, it is easier to have + # it all in one place: here + output = f''' +
+
{date}
+
{author}, {others}
+
{place} - {title}
+ {entry} +
T/U {tu} hrs
''' + return render( + request, + "logbookform.html", + { + "form": form, + "year": year, + "author": author, + "output": output, + }, + ) + # GET here + else: + form = LogbookEditForm() + + return render( + request, + "logbookform.html", + { + "form": form, + "year": year, + "author": author, + }, + ) + + @login_required_if_public diff --git a/templates/logbookform.html b/templates/logbookform.html index 1521ef2..69a671f 100644 --- a/templates/logbookform.html +++ b/templates/logbookform.html @@ -13,7 +13,9 @@

{% endif %}
@@ -67,9 +69,9 @@ label = "tu" name = "tu" size="5" title="Time underground (hours)" placeholder="0.1" /> -

This DOES NOT WORK yet +

This DOES NOT SAVE ANYTHING yet @@ -82,5 +84,39 @@
- +{% if output %} +This is the HTML which will be put into the logbook.html, and below that is the HTML as rendered to be read as part of the full logbook. +
+{{output}}
+
+
+ +{{output|safe}} +{% endif %} {% endblock %} \ No newline at end of file