|
@@ -4,9 +4,10 @@ Created on Sat Apr 22 17:07:13 2022
|
|
|
|
|
|
@author: Hammerle
|
|
|
"""
|
|
|
+import time
|
|
|
import json
|
|
|
import requests
|
|
|
-from flask import Flask, render_template
|
|
|
+from flask import Flask, render_template, request, flash
|
|
|
|
|
|
|
|
|
# FOLDER = "src/" # docker
|
|
@@ -21,7 +22,8 @@ with open(f"{FOLDER}secret_key", "rb") as secretKeyFile:
|
|
|
|
|
|
@app.route("/", methods=["GET"])
|
|
|
def index():
|
|
|
- return render_template("index.html")
|
|
|
+ welcome_cards = read_database("welcome")
|
|
|
+ return render_template("index.html", cards=welcome_cards)
|
|
|
|
|
|
|
|
|
@app.route("/karte", methods=["GET"])
|
|
@@ -38,24 +40,41 @@ def steps():
|
|
|
|
|
|
@app.route("/events", methods=["GET"])
|
|
|
def events():
|
|
|
- boudicca_req = requests.get("https://api.boudicca.events/event")
|
|
|
+ boudicca_req = requests.get("https://api.boudicca.events/events")
|
|
|
events = []
|
|
|
if boudicca_req.status_code == 200:
|
|
|
events = boudicca_req.json()
|
|
|
return render_template('events.html', events=events)
|
|
|
|
|
|
|
|
|
-@app.route("/mitgestaltung", methods=["GET"])
|
|
|
+@app.route("/mitgestalten", methods=["GET", "POST"])
|
|
|
def contribute():
|
|
|
+ if request.method == "POST":
|
|
|
+ contribution = {
|
|
|
+ "fullname": request.form.get("fullname"),
|
|
|
+ "email": request.form.get("email"),
|
|
|
+ "message": request.form.get("message"),
|
|
|
+ "timestamp": time.time()
|
|
|
+ }
|
|
|
+ add_to_database("contribute", contribution)
|
|
|
+
|
|
|
+ flash("Danke für's Mitmachen!", "success")
|
|
|
return render_template("contribute.html")
|
|
|
|
|
|
|
|
|
-def read_database(name):
|
|
|
- with open(f"{FOLDER}database_{name}.json") as file:
|
|
|
+def read_database(db_name):
|
|
|
+ with open(f"{FOLDER}database/db_{db_name}.json") as file:
|
|
|
db_data = json.load(file)
|
|
|
return db_data
|
|
|
|
|
|
|
|
|
+def add_to_database(db_name, data_to_add):
|
|
|
+ db_data = read_database(db_name)
|
|
|
+ db_data.append(data_to_add)
|
|
|
+ with open(f"{FOLDER}database/db_{db_name}.json", "w") as file:
|
|
|
+ json.dump(db_data, file, indent=4)
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
app.run() # localhost
|
|
|
# app.run(host="0.0.0.0") # in network
|