1
0

6 Коммиты 2b0df5b7b2 ... 95c010ff14

Автор SHA1 Сообщение Дата
  Bernadette Elena Hammerle 95c010ff14 map: fix urls 1 год назад
  Bernadette Elena Hammerle 37399b95dd added database to folder 1 год назад
  Bernadette Elena Hammerle c344ff5655 added w-cards on index page 1 год назад
  Bernadette Elena Hammerle 3c87142b9d add form and json db for user contribution 1 год назад
  Bernadette Elena Hammerle 0be0b7affe map: added js and css resources to map only 1 год назад
  Bernadette Elena Hammerle 2d6547774b changed boudicca api url; added thanks; handle empty result 1 год назад

+ 25 - 6
app.py

@@ -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

+ 14 - 0
database/db_contribute.json

@@ -0,0 +1,14 @@
+[
+    {
+        "fullname": "1",
+        "email": "2@2",
+        "message": "23",
+        "timestamp": 1682365205.378369
+    },
+    {
+        "fullname": "132",
+        "email": "1@asd",
+        "message": "1231",
+        "timestamp": 1682365212.381221
+    }
+]

+ 6 - 6
database_map.json → database/db_map.json

@@ -11,7 +11,7 @@
                 "shortdescription": "Wir sind das größte kommunale Klimaschutz-Netzwerk Österreichs. Wir setzen lokale Klimaschutz-Initiativen und schützen gleichzeitig den Amazonas-Regenwald. Und das bereits seit 1990."
             }, {
                 "name": "kim",
-                "url": "kimz.at",
+                "url": "https://kimz.at",
                 "long": 48.198655456853174,
                 "lat": 13.952166412848625,
                 "shortdescription": "Klimaschutz. Ideen. Möglichkeiten."
@@ -23,7 +23,7 @@
                 "shortdescription": "Wir sehen uns als Anlaufstelle für alle, die die Umsetzung von konkreten Schritten zur Energiewende unterstützen wollen und damit einen Beitrag zu lokalen und globalen Klimaschutz leisten."
             }, {
                 "name": "Grünschnabel",
-                "url": "gruenschnabel.at",
+                "url": "https://gruenschnabel.at",
                 "long": 48.31066139162836,
                 "lat": 14.276978012854087,
                 "shortdescription": "Grünschnabel ist ein Projekt des Vereins zur Förderung von Lebensqualität."
@@ -51,13 +51,13 @@
         "liste":
         [{
                 "name": "SoLaWi Gmias!",
-                "url": "www.gmias.at",
+                "url": "https://www.gmias.at",
                 "long": 48.27380161125205,
                 "lat": 14.228417930779035,
                 "shortdescription": "In unserer solidarischen Landwirtschaft bauen wir regional, saisonal und biologisch Gemüse an."
             }, {
                 "name": "Futter Natur Gemüse aus Bergern",
-                "url": "www.futter-natur.at",
+                "url": "https://www.futter-natur.at",
                 "long": 48.24057134126316,
                 "lat": 13.931337548703123,
                 "shortdescription": "Die Herausforderungen unserer Zeit brauchen die Vision einer guten Zukunft, den Mut anzupacken und Menschen, die den ersten Schritt gehen."
@@ -70,13 +70,13 @@
         "liste":
         [{
                 "name": "Franckkistl",
-                "url": "www.franckkistl.at",
+                "url": "https://www.franckkistl.at",
                 "long": 48.295286122494524,
                 "lat": 14.314487701213688,
                 "shortdescription": "Die Foodcoop Franck Kistl steht für Ernährungssouveränität, gute Nachbarschaft, Nachhaltigkeit, Solidarität, Umweltschutz und neue Ideen."
             }, {
                 "name": "EKG Linz",
-                "url": "ekglinz.fcoop.at",
+                "url": "https://ekglinz.fcoop.at",
                 "long": 48.30620307928006,
                 "lat": 14.290096170525898,
                 "shortdescription": ""

+ 0 - 0
database_steps.json → database/db_steps.json


+ 22 - 0
database/db_welcome.json

@@ -0,0 +1,22 @@
+[
+ {
+  "title": "Was?",
+  "subtitle": "Klimafreundlich und bequem",
+  "text": "Nach & Nach ist ein Projekt, das Menschen helfen soll ihr Leben nach und nach klimafreundlicher zu gestalten, indem es kleine nachhaltige Schritte und Initiativen in der Nachbarschaft aufzeigt."
+ },
+ {
+  "title": "Wann?",
+  "subtitle": "Ideenwerkstatt",
+  "text": "Das Projekt ist im Rahmen von UpdateSocial im April 2023 entstanden.",
+  "url": "https://updatesocial.org/"
+ },
+ {
+  "title": "Wer?",
+  "subtitle": "Unser Team",
+  "text": "Fünf motivierte UpdateSocial-Teilnehmer*innen mit Unterstützung von zahlreichen Experten*innen."
+ },
+ {
+  "title": "Warum?",
+  "text": "Weil wir etwas verändern wollen."
+ }
+]

+ 5 - 0
static/css/main.css

@@ -49,3 +49,8 @@ nav a svg, nav a i {
     height: calc(100vh - 120px - 2em);
     min-height: 200px;
 }
+
+.btn-success{
+    --bs-btn-bg: var(--dark-bg);
+    --bs-btn-border-color: var(--dark-bg);
+}

+ 28 - 0
templates/contribute.html

@@ -3,4 +3,32 @@
 {% block content %}
     <h2>Mitgestalten</h2>
 
+    <form action="/mitgestalten" method="post" >
+        <div class="mb-3">
+            <label for="fullname" class="form-label mb-1">Name</label>
+            <input type="text" class="form-control" id="fullname" name="fullname">
+        </div>
+        <div class="mb-3">
+            <label for="email" class="form-label mb-1">Email-Adresse</label>
+            <input type="email" class="form-control" id="email" name="email">
+        </div>
+
+        <div class="mb-3">
+            <label for="message" class="form-label mb-1">Deine Wünsche, Ideen und Anregungen für <em>Nach & Nach</em>:</label>
+            <textarea class="form-control" id="message" name="message" rows="3"></textarea>
+        </div>
+        <button type="submit" class="btn btn-success mb-3">Senden</button>
+    </form>
+
+    {% with messages = get_flashed_messages(with_categories=true) %}
+        {% if messages %}
+            {% for category, message in messages %}
+                <div class="alert alert-{{ category }} alert-dismissible" role="alert">
+                    {{ message }}
+                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+                </div>
+            {% endfor %}
+        {% endif %}
+    {% endwith %}
+
 {% endblock %}

+ 24 - 15
templates/events.html

@@ -3,24 +3,33 @@
 {% block content %}
     <h2>Events</h2>
 
-    {% for event in events %}
-      <div class="card mb-2">
-        <div class="card-body">
-          <h5 class="card-title">{{event.name}}</h5>
-          <h6 class="card-subtitle mb-2 text-muted">{{event.startDate}}</h6>
+    {% if events|length %}
+        {% for event in events %}
+          <div class="card mb-2">
+            <div class="card-body">
+              <h5 class="card-title">{{event.name}}</h5>
+              <h6 class="card-subtitle mb-2 text-muted">{{event.startDate}}</h6>
 
-          {% for key, val in event["data"].items() %}
-              {% if "url" in key %}
-                  <a href="{{val}}" class="card-link mb-0">{{val}}</a>
-              {% else %}
-                  <p class="card-text mb-0">{{key}}: {{val}}</p>
-              {% endif %}
+              {% for key, val in event["data"].items() %}
+                  {% if "url" in key %}
+                      <a href="{{val}}" class="card-link mb-0">{{val}}</a>
+                  {% else %}
+                      <p class="card-text mb-0">{{key}}: {{val}}</p>
+                  {% endif %}
+              {% endfor %}
 
-
-          {% endfor %}
+            </div>
+          </div>
+        {% endfor %}
+    {% else %}
+        <div class="card mb-2">
+          <div class="card-body">
+              <p class="card-text mb-0">Derzeit sind keine Events geplant.</p>
+          </div>
         </div>
-      </div>
-    {% endfor %}
+    {% endif %}
+
+    <p><small class="fst-italic">Vielen Dank an das Team von <a href="https://boudicca.events/">boudicca.events</a>! :)</small></p>
 
 
 {% endblock %}

+ 15 - 0
templates/index.html

@@ -3,4 +3,19 @@
 {% block content %}
 <h2>Herzlich Willkommen bei Nach & Nach </h2>
 
+{% for card in cards %}
+    <div class="card mb-2">
+      <div class="card-body">
+        <h5 class="card-title">{{card.title}}</h5>
+        {% if card.subtitle %}
+            <h6 class="card-subtitle mb-2 text-muted">{{card.subtitle}}</h6>
+        {% endif %}
+        <p class="card-text mb-0">{{card.text}}</p>
+        {% if card.url %}
+            <a href="{{card.url}}" class="card-link">{{card.url}}</a>
+        {% endif %}
+      </div>
+    </div>
+{% endfor %}
+
 {% endblock %}

+ 5 - 15
templates/layout.html

@@ -12,18 +12,8 @@
         <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" />
         <link href="{{ url_for('static', filename='css/main.css') }}" rel="stylesheet">
 
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js" integrity="sha512-rmZcZsyhe0/MAjquhTgiUcb4d9knaFc7b5xAfju483gbEXTkeJRUMIPk6s3ySZMYUHEcjKbjLjyddGWMrNEvZg==" crossorigin="anonymous"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
-
-        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"
-             integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI="
-             crossorigin=""/>
-        <script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"
-             integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM="
-             crossorigin=""></script>
-        <link rel="stylesheet" href="static/css/leaflet.awesome-markers.css">
-        <script src="static/js/leaflet.awesome-markers.js"></script>
-        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+        {% block head_links %}
+        {% endblock %}
 
     </head>
     <body>
@@ -62,9 +52,9 @@
                     <i class="bi bi-calendar-day" title="Events" aria-hidden="true"></i>
                     <span>Events</span>
                 </a>
-                <a class="nav-link pt-0 pb-0 p-0" href="/mitgestaltung">
-                    <i class="bi bi-people" title="Mitgestaltung" aria-hidden="true"></i>
-                    <span>Mitgestaltung</span>
+                <a class="nav-link pt-0 pb-0 p-0" href="/mitgestalten">
+                    <i class="bi bi-people" title="Mitgestalten" aria-hidden="true"></i>
+                    <span>Mitgestalten</span>
                 </a>
             </nav>
 

+ 16 - 0
templates/map.html

@@ -1,5 +1,21 @@
 {% extends "layout.html" %}
 
+{% block head_links %}
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js" integrity="sha512-rmZcZsyhe0/MAjquhTgiUcb4d9knaFc7b5xAfju483gbEXTkeJRUMIPk6s3ySZMYUHEcjKbjLjyddGWMrNEvZg==" crossorigin="anonymous"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
+
+    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"
+         integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI="
+         crossorigin=""/>
+    <script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"
+         integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM="
+         crossorigin=""></script>
+    <link rel="stylesheet" href="static/css/leaflet.awesome-markers.css">
+    <script src="static/js/leaflet.awesome-markers.js"></script>
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+{% endblock %}
+
+
 {% block content %}
 <div id="map"></div>