From c8baca3c05496dc92becdfdfb8fb2dba28daee3f Mon Sep 17 00:00:00 2001 From: Beaumont Mogridge <mogridgeb@cardiff.ac.uk> Date: Thu, 1 Dec 2022 19:47:50 +0000 Subject: [PATCH] Update templates/Space.html, WorkSpaces.sql, main.py --- WorkSpaces.sql | 18 +++++++++++++ main.py | 42 +++++++++++++----------------- templates/Space.html | 61 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 92 insertions(+), 29 deletions(-) diff --git a/WorkSpaces.sql b/WorkSpaces.sql index f39b959..67a3cb6 100644 --- a/WorkSpaces.sql +++ b/WorkSpaces.sql @@ -1 +1,19 @@ DELETE FROM 'coworking_spaces' WHERE Name = 'Name'; +--DROP TABLE IF EXISTS coworking_spaces; + + +--CREATE TABLE IF NOT EXISTS 'coworking_spaces' ( +--`Name` TEXT NOT NULL, +--`Address` TEXT NOT NULL, +--`Main_Photo` TEXT NOT NULL, +--`Additional_photos` TEXT NOT NULL, +--`Description` TEXT NOT NULL, +--`Website` TEXT NOT NULL, +--`Email` TEXT NOT NULL, +--`Phone_Number` TEXT NOT NULL, +--`Opening_Hours` TEXT NOT NULL, +--`Checkin_Instructions` TEXT NOT NULL, +--); + + +--INSERT INTO 'coworking_spaces'('Name','Address', 'Main_Photo', 'Additional_photos','Description','Website','Email','Phone_Number','Opening_Hours','Checkin_Instructions') VALUES ('Codebase CodeBase Edinburgh' , '37a Castle Terrace, Edinburgh, EH1 2EL ', 'https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646867535415-4JI39H286BUMT26H4FHN/C36A1915.jpg?format=2500w',' https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646868533510-J1OT4PEG5VM9FCBF8BJE/15.10.19_-_CREATIVE_BRIDGE_C02_-_DAY01_-_LQ-19+%281%29.jpg?format=2500w','https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646868421127-07KQ4N1OHTDDKQME686A/15.10.19_-_CREATIVE_BRIDGE_C02_-_DAY01_-_LQ-52+%281%29.jpg?format=2500w', 'Hi. We’re CodeBase. We've been exploring the world of startups and innovation for over five years now. We're not really sure how to best describe what we do, but we think the words "tech cluster" probably do it best. Please get in touch! We’re friendly people who are geeky about building tech startups, managing disruption and innovation.', 'https://www.thisiscodebase.com','info@thisiscodebase.com','(+44) 0131 560 2003', '08:00 - 17:00',' Use the email address or phone number to call ahead and book a desk, let them know you're a Tramshed member'); diff --git a/main.py b/main.py index 6eac520..58fd4f5 100644 --- a/main.py +++ b/main.py @@ -6,35 +6,29 @@ DATABASE = "db.db" ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) app = Flask(__name__) -@app.route("/Load/CodeBase", methods = ['GET','POST']) +@app.route("/Load/CodeBase") def Load(): - if request.method =='GET': - return render_template('Space.html') - if request.method =='POST': - try: Name = "CodeBase"; conn = sqlite3.connect(DATABASE) cur = conn.cursor() - document.getElementById("name").innerHTML= Name; - cur.execute("SELECT Address FROM coworking_spaces WHERE Name =? ;", [Name]) - Address = cur.fetch(); - cur.execute("SELECT Main_Photo FROM coworking_spaces WHERE Name =? ;", [Name]) - Main_Photo = cur.fetch(); - cur.execute("SELECT Additional_photos FROM coworking_spaces WHERE Name =? ;", [Name]) - Additional_photos = cur.fetch(); - cur.execute("SELECT Description FROM coworking_spaces WHERE Name =? ;", [Name]) - Description = cur.fetch(); - cur.execute("SELECT Website FROM coworking_spaces WHERE Name =? ;", [Name]) - Website = cur.fetch(); - cur.execute("SELECT Opening_Hours FROM coworking_spaces WHERE Name =? ;", [Name]) - Opening_Hours = cur.fetch(); - except: - print('error', data) - conn.close() - finally: - conn.close() + cur.execute("SELECT * FROM coworking_spaces WHERE Name = 'CodeBase';") + data = cur.fetchall() + print(data) + # cur.execute("SELECT Address FROM coworking_spaces WHERE Name =? ;", [Name]) + # Address = cur.fetchall() + # cur.execute("SELECT Main_Photo FROM coworking_spaces WHERE Name =? ;", [Name]) + # Main_Photo = cur.fetchall() + # cur.execute("SELECT Additional_photos FROM coworking_spaces WHERE Name =? ;", [Name]) + # Additional_photos = cur.fetchall() + # cur.execute("SELECT Description FROM coworking_spaces WHERE Name =? ;", [Name]) + # Description = cur.fetchall() + # cur.execute("SELECT Website FROM coworking_spaces WHERE Name =? ;", [Name]) + # Website = cur.fetchall() + # cur.execute("SELECT Opening_Hours FROM coworking_spaces WHERE Name =? ;", [Name]) + # Opening_Hours = cur.fetchall() + return render_template('Space.html', data = data) return str(data) - + conn.close() diff --git a/templates/Space.html b/templates/Space.html index 71be495..62c2459 100644 --- a/templates/Space.html +++ b/templates/Space.html @@ -1,15 +1,40 @@ {%extends 'OurSpaces.html'%} <form id='myForm' action='/Load/CodeBase>' method ='post'> {% block titleBlock%} - <p id="name"></p> - <img src= Main_Photo ><br>"/> - <script> -document.getElementById("name").innerHTML = Name; + <h1 id="name"></h1><br> + <td>data</td> + <img src= Main_Photo><br> +<<script type="text/javascript"> + document.getElementById("name").innerHTML= data; </script> +<table border = 1> + <thead> + <td>Name</td> + <td>Address</td> + <td>Main_Photo</td> + <td>Additional_photos</td> + <td>Description</td> + <td>Website</td> + <td>Opening_Hours</td> + </thead> + + {% for row in data %} + + <tr> + <td>{{row[0]}}</td> + <td>{{row[1]}}</td> + <td>{{row[2]}}</td> + <td>{{row[3]}}</td> + <td>{{row[4]}}</td> + <td>{{row[5]}}</td> + <td>{{row[6]}}</td> + </tr> + {% endfor %} +</table> {%endblock%} {% block addressBlock%} - <h2><input type = "text" name = "Name"><br></h2> + <h2><br></h2> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d4957.954181608377!2d-2.999839445369478!3d51.58698324808131!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x4871e6cc3bd82553%3A0x684c1227f14b4a15!2sNational%20Software%20Academy%20(Cardiff%20University)!5e0!3m2!1sen!2suk!4v1669722978098!5m2!1sen!2suk" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe> {%endblock%} @@ -31,6 +56,32 @@ document.getElementById("name").innerHTML = Name; <span id='txt'></span> +<script> + function loadSpace() { + var Name = document.forms["coworking_spaces"]["Name"].value; + var Address = document.forms["coworking_spaces"]["Address"].value; + var Main_Photo = document.forms["coworking_spaces"]["Main_Photo"].value; + var Additional_photos = document.forms["coworking_spaces"]["Main_Photo"].value; + var Description = document.forms["coworking_spaces"]["Description"].value; + var Website = document.forms["coworking_spaces"]["Website"].value; + var Opening_Hours = document.forms["coworking_spaces"]["Opening_Hours"].value; + + var xhttp = new XMLHttpRequest(); + + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.onload = function() { + if (xhttp.readyState === 4 && xhttp.status === 200) { + console.log(xhttp.responseText); + document.getElementById("txt").innerHTML = xhttp.responseText; + } else { + console.error(xhttp.statusText); + } + }; + xhttp.send(params); + return false; + } + +</script> </form> -- GitLab