From 5c3ca6099efaf31fd1e614541f1f87942873eeb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rnR?= Date: Wed, 2 Nov 2022 22:05:21 +0100 Subject: [PATCH] erste dinger drin --- .gitignore | 2 ++ runServer.sh | 2 +- voctrain.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 voctrain.py diff --git a/.gitignore b/.gitignore index e69de29..34c44b0 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +vokabeln.db diff --git a/runServer.sh b/runServer.sh index 171d2ee..9fb3d80 100755 --- a/runServer.sh +++ b/runServer.sh @@ -2,5 +2,5 @@ # # startet den Flask Server in Python # -FLASK_APP=gastCheckIn.py FLASK_ENV=production flask run -p 5001 +FLASK_APP=voctrain.py FLASK_ENV=development flask run -p 5003 diff --git a/voctrain.py b/voctrain.py new file mode 100644 index 0000000..05a57d2 --- /dev/null +++ b/voctrain.py @@ -0,0 +1,42 @@ +import sqlite3 +from flask import Flask, render_template, request, url_for, flash, redirect +from werkzeug.exceptions import abort + +def get_db_connection(): + conn = sqlite3.connect('vokabeln.db') + conn.row_factory = sqlite3.Row + return conn + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'ClubhouseHurriedBoxerMosaicUnlawfulWanted' + +@app.route('/', methods=('GET', 'POST')) +def index(): + + + if request.method == 'POST': + vorname = request.form['vorname'] + nachname = request.form['nachname'] + telefonnummer = request.form['telefonnummer'] + emailadresse = request.form['emailadresse'] + anschrift = request.form['anschrift'] + if telefonnummer == '' and emailadresse == '' and anschrift == '': + flash('Mindestens eine Eingabe zur Erreichbarkeit muss angegeben werden.','error') + else: + conn = get_db_connection() + conn.execute("INSERT INTO guests ( vorname , nachname, telefonnummer, emailadresse, anschrift) VALUES (?, ?, ?, ?, ?)", + (vorname , nachname, telefonnummer, emailadresse, anschrift) + ) + conn.commit() + conn.close() + flash('Vielen Dank ' + vorname + ' ' + nachname + ' und viel Freude bei der Veranstaltung!','success') + return redirect(url_for('index')) + + + conn = get_db_connection() + guests = conn.execute('SELECT * FROM guests').fetchall() + conn.close() + return render_template('index.html', guests=guests) + +if __name__ == '__main__': + app.run()