From e8d1d7e31e51ccd2df5a8630bbccb66c6ddbf807 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Tue, 9 Nov 2021 17:39:36 +0100 Subject: [PATCH] improve form creation --- datentrog.py | 29 ++++++++++++++----------- datentrog.tpl | 49 ------------------------------------------- static/new.html | 20 ------------------ template/event.tpl | 37 ++++++++++++++++++++++++++++++++ template/new.tpl | 11 ++++++++++ template/toplevel.tpl | 14 +++++++++++++ 6 files changed, 79 insertions(+), 81 deletions(-) delete mode 100644 datentrog.tpl delete mode 100644 static/new.html create mode 100644 template/event.tpl create mode 100644 template/new.tpl create mode 100644 template/toplevel.tpl diff --git a/datentrog.py b/datentrog.py index 6a87d03..f68841f 100755 --- a/datentrog.py +++ b/datentrog.py @@ -19,30 +19,35 @@ cursor.execute(""" @application.get("/") -def root_get(): - return bottle.static_file("new.html", root="static") - - -@application.get("/static/") -def datentrog_get(file): - return bottle.static_file(file, root="static") +@bottle.view("template/new.tpl") +def new_get(): + pass @application.post("/") -def datentrog_post(): - bottle.redirect("event/" + bottle.request.forms.get("event", "")) +@bottle.view("template/new.tpl") +def new_post(): + event = bottle.request.forms.get("event", "") + if event: + bottle.redirect("event/" + event) + return dict(event=event, feedback=True) + + +@application.get("/static/") +def static_get(file): + return bottle.static_file(file, root="static") @application.get("/event/") -@bottle.view("datentrog.tpl") +@bottle.view("template/event.tpl") def event_get(event): return dict(event=event) @application.post("/event/") -@bottle.view("datentrog.tpl") +@bottle.view("template/event.tpl") def event_post(event): - data = {"feedback": True, "success": True} + data = dict(feedback=True, success=True) for field in ("event", "name", "address", "contact"): data[field] = bottle.request.forms.get(field, "") data["success"] = data["success"] and data[field] diff --git a/datentrog.tpl b/datentrog.tpl deleted file mode 100644 index f35bb9d..0000000 --- a/datentrog.tpl +++ /dev/null @@ -1,49 +0,0 @@ - - - - Corona-Kontaktformular - {{ get("event", "Heizhaus") }} - - - - -
-

Corona-Kontaktformular

- % if get("success", False): -

Erfolgreich registriert.

-
- -
- % else: -

Die Daten werden nach 1 Monat gelöscht und ausschließlich zur Corona-Kontaktverfolgung verwendet.

-
-
- - -
-
- - - % if get("feedback", False): - - % end -
-
- - - % if get("feedback", False): - - % end -
-
- - - % if get("feedback", False): - - % end -
- -
- % end -
- - diff --git a/static/new.html b/static/new.html deleted file mode 100644 index 52fd226..0000000 --- a/static/new.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - Corona-Kontaktformular - Neu erstellen - - - - -
-

Corona-Kontaktformular

-
-
- - -
- -
-
- - diff --git a/template/event.tpl b/template/event.tpl new file mode 100644 index 0000000..5f5f816 --- /dev/null +++ b/template/event.tpl @@ -0,0 +1,37 @@ +% rebase('template/toplevel.tpl', title=event) +% if get("success", False): +

Erfolgreich registriert.

+
+ +
+% else: +

Die Daten werden nach 1 Monat gelöscht und ausschließlich zur Corona-Kontaktverfolgung verwendet.

+
+
+ + +
+
+ + + % if get("feedback", False): + + % end +
+
+ + + % if get("feedback", False): + + % end +
+
+ + + % if get("feedback", False): + + % end +
+ +
+% end diff --git a/template/new.tpl b/template/new.tpl new file mode 100644 index 0000000..2de6f27 --- /dev/null +++ b/template/new.tpl @@ -0,0 +1,11 @@ +% rebase('template/toplevel.tpl', title='Neu erstellen') +
+
+ + + % if get("feedback", False): + + % end +
+ +
diff --git a/template/toplevel.tpl b/template/toplevel.tpl new file mode 100644 index 0000000..acf1ce1 --- /dev/null +++ b/template/toplevel.tpl @@ -0,0 +1,14 @@ + + + + Corona-Kontaktformular - {{ get("title", "Heizhaus") }} + + + + +
+

Corona-Kontaktformular

+ {{!base}} +
+ +