From fc0751cbbe54455506dd0afa21069b35e6fde139 Mon Sep 17 00:00:00 2001 From: Liam Driscoll <driscolll4@cardiff.ac.uk> Date: Fri, 9 Dec 2022 13:26:04 +0000 Subject: [PATCH] Adding locations and template route. --- project_server.py | 39 ++++++++++++++++++++++++++++++++++-- templates/ListLocations.html | 26 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 templates/ListLocations.html diff --git a/project_server.py b/project_server.py index 24fb47d..b1c6bb5 100644 --- a/project_server.py +++ b/project_server.py @@ -1,9 +1,10 @@ import os import sqlite3 -from flask import Flask, redirect, request, render_template, jsonify +from flask import Flask, redirect, request, render_template, jsonify, url_for, flash, session app = Flask(__name__) DATABASE = "project_db.db" +app.secret_key = "hello" ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) @@ -27,6 +28,16 @@ def returnManageCoworkingSpaces(): if (request.method == 'GET'): return render_template("Manage_Coworking_Spaces.html") +@app.route("/ListLocations", methods=['GET']) +def returnListLocations(): + if (request.method =='GET'): + conn = connect_db() + cur = conn.cursor() + cur.execute("SELECT Name, Main_Photo FROM coworking_spaces") + locationData = cur.fetchall() + conn.close() + return render_template("ListLocations.html", data = locationData) + @app.route("/Load/CodeBase") def Load(): Name = "Codebase"; @@ -59,7 +70,6 @@ def Load(): return render_template('Space.html', data = data) # pageAddress = Address, pageMain_Photo = Main_Photo, pageAdditional_photos = Additional_photos, pageDescription = Description, pageWebsite = Website, pageOpening_Hours = Opening_Hours ) - @app.route("/SearchRecord", methods=['POST', 'GET']) def searchRecord(): @@ -177,5 +187,30 @@ def updateRecord(): print(infoMessage) return (infoMessage) +@app.route("/locations", methods=["POST" , "GET"]) +def Locations(): + + print('Processing location') + + if request.method == "POST": + session.permanent = True + locationsName = request.form['name'] + locationPic = request.form['image'] + + + conn = sqlite3.connect(DATABASE) + cur = conn.cursor() + cur.execute("SELECT Name, Main_photo FROM coworking_spaces WHERE Name= ?;", [locationsName]) + conn.commit() + conn.close() + + msg= " Location added successfuly!" + + return render_template('locations.html') + + + + + if __name__ == "__main__": app.run(debug=True) diff --git a/templates/ListLocations.html b/templates/ListLocations.html new file mode 100644 index 0000000..e7d8052 --- /dev/null +++ b/templates/ListLocations.html @@ -0,0 +1,26 @@ +{%extends "base_template.html"%} + +{%block headblock%} + <title> Locations </title> +{%endblock%} + +{%block headerblock%} + <a id="headerText" + href="ListLocations"> + Locations</a> +{%endblock%} + +{%block mainblock%} +<br><br> +{%if data%} + {%for x in range(data|length)%} + {{data[x][0]}} + {{data[x][1]}} + <br><br> + {%endfor%} +{%endif%} + +{%endblock%} + +{%block jsblock%} +{%endblock%} -- GitLab