|
@@ -4,9 +4,10 @@ Created on Sat Apr 22 17:07:13 2022
|
|
|
|
|
|
@author: Hammerle
|
|
@author: Hammerle
|
|
"""
|
|
"""
|
|
|
|
+import time
|
|
import json
|
|
import json
|
|
import requests
|
|
import requests
|
|
-from flask import Flask, render_template
|
|
|
|
|
|
+from flask import Flask, render_template, request, flash
|
|
|
|
|
|
|
|
|
|
# FOLDER = "src/" # docker
|
|
# FOLDER = "src/" # docker
|
|
@@ -45,17 +46,34 @@ def events():
|
|
return render_template('events.html', events=events)
|
|
return render_template('events.html', events=events)
|
|
|
|
|
|
|
|
|
|
-@app.route("/mitgestaltung", methods=["GET"])
|
|
|
|
|
|
+@app.route("/mitgestalten", methods=["GET", "POST"])
|
|
def contribute():
|
|
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")
|
|
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_name}.json") as file:
|
|
db_data = json.load(file)
|
|
db_data = json.load(file)
|
|
return db_data
|
|
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_name}.json", "w") as file:
|
|
|
|
+ json.dump(db_data, file, indent=4)
|
|
|
|
+
|
|
|
|
+
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
app.run() # localhost
|
|
app.run() # localhost
|
|
# app.run(host="0.0.0.0") # in network
|
|
# app.run(host="0.0.0.0") # in network
|