diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..98feee92f790f8537a788150b9b993f2db938bfe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +.vscode/ +database.db diff --git a/database.py b/database.py new file mode 100644 index 0000000000000000000000000000000000000000..80ca1c68bdcbcf975ff4f765120d2f2cc4c57244 --- /dev/null +++ b/database.py @@ -0,0 +1,100 @@ +import os +import sqlite3 +from typing import List + +DATABASE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "database.db") + +class Connection: + def __init__(self): + self.connection = sqlite3.connect(DATABASE) + self.cursor = self.connection.cursor() + self.do_rollback = False + + def commit(self): + self.connection.commit() + self.do_rollback = False + + def execute(self, sql: str, tuple = ()): + self.do_rollback = True + self.cursor.execute(sql, tuple) + + def fetch_all(self): + return self.cursor.fetchall() + + def close(self): + if self.do_rollback: + self.connection.rollback() + + self.connection.close() + + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + +with Connection() as conn: + conn.execute('''CREATE TABLE IF NOT EXISTS Workspaces ( + id integer NOT NULL PRIMARY KEY AUTOINCREMENT, + name text NOT NULL, + address text NOT NULL, + main_photo text NOT NULL, + description text NOT NULL, + website text NOT NULL, + email text NOT NULL, + phone_number text NOT NULL, + opening_hours text, + checkin_instructions text)''') + conn.execute('''CREATE TABLE IF NOT EXISTS AdditionalPhotos ( + id integer NOT NULL PRIMARY KEY AUTOINCREMENT, + url text NOT NULL, + workspace_id integer NOT NULL, + FOREIGN KEY (workspace_id) REFERENCES Workspaces(id))''') + conn.commit() + +class Workspace: + def __init__(self, name: str, + address: str, main_photo: str, additional_photos: List[str], description: str, + website: str, email: str, phone_number: str, opening_hours: str, checkin_instructions: str): + self.id = None + self.name = name + self.address = address + self.main_photo = main_photo + self.additional_photos = additional_photos + self.description = description + self.website = website + self.email = email + self.phone_number = phone_number + self.opening_hours = opening_hours + self.checkin_instructions = checkin_instructions + + def from_query(conn, tuple): + (id, name, address, main_photo, description, website, email, phone_number, opening_hours, checkin_instructions) = tuple + additional_photos = [] + + conn.execute("SELECT url FROM AdditionalPhotos WHERE workspace_id = ?", ("1")) + for x in conn.cursor.fetchall(): + additional_photos.append(x[0]) + + workspace = Workspace(name, address, main_photo, additional_photos, description, website, email, phone_number, opening_hours, checkin_instructions) + workspace.id = id + return workspace + +def add_workspace(workspace: Workspace): + with Connection() as conn: + conn.execute( + "INSERT INTO Workspaces (name, address, main_photo, description, website, email, phone_number, opening_hours, checkin_instructions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", + (workspace.name, workspace.address, workspace.main_photo, workspace.description, workspace.website, workspace.email, workspace.phone_number, workspace.opening_hours, workspace.checkin_instructions) + ) + id = conn.cursor.lastrowid + for url in workspace.additional_photos: + conn.execute("INSERT INTO AdditionalPhotos (url, workspace_id) VALUES (?, ?)", (url, id)) + conn.commit() + return id + +def get_workspaces(): + with Connection() as conn: + conn.execute("SELECT * FROM Workspaces") + return [Workspace.from_query(conn, x) for x in conn.cursor.fetchall()] + +print(get_workspaces()) \ No newline at end of file diff --git a/import_database.py b/import_database.py new file mode 100644 index 0000000000000000000000000000000000000000..deceed40a826f436a7db3a2546563523db90b263 --- /dev/null +++ b/import_database.py @@ -0,0 +1,14 @@ +import database + +print(database.add_workspace(database.Workspace( + "CodeBase", + "CodeBase Edinburgh, 37a Castle Terrace, Edinburgh, EH1 2EL", + "https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1505921023376-PAHUDHVOOKIYF4XQPHOO/5951229048_3e3d50fcb1_o.jpg?format=750w", + ["https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1636387943314-W9JWMS6ZX4DEZSPUV7T0/Copy+of+Unfiltered_square+%281%29.png?format=500w"], + "We've been exploring the world of startups...", + "https://www.thisiscodebase.com", + "hannah@thisiscodebase.com", + "+44 131 560 2003", + "Monday - Friday, 9am - 5pm", + "Tramsched members should contact Hannah using the email address listed." +))) diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..dc32f70e33060652797c6da10c685ca13c1bac44 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +from flask import Flask, request, render_template +import database + +app = Flask(__name__) + +@app.route("/", methods = ["GET"]) +def home(): + if request.method == "GET": + workspaces = database.get_workspaces() + return render_template("home.html", workspaces = workspaces) + +if __name__ == "__main__": + app.run(debug = True) diff --git a/Tramshed_Logo.jpg b/static/Tramshed_Logo.jpg similarity index 100% rename from Tramshed_Logo.jpg rename to static/Tramshed_Logo.jpg diff --git a/style.css b/static/style.css similarity index 85% rename from style.css rename to static/style.css index b837fd959526379ca09b60d73cb35eaca48474db..640879bec84c1a5f8b9b2c04f308c0a357fdc125 100644 --- a/style.css +++ b/static/style.css @@ -1,13 +1,7 @@ h1 { color: blue;} -button -{color: greenyellow; -border-spacing: 20px; -size: 4000000px; -} - -li { +nav li { display: inline; border-right: 1px solid #bbb; float:left; @@ -15,14 +9,14 @@ li { border-bottom-right-radius: 1000%; } -li:last-child { +nav li:last-child { color: red; background-color: red; border-right: none; border-top-left-radius: 1000%; border-bottom-left-radius: 1000%; } -ul { +nav ul { list-style-type: none; margin: 0; padding: 0; @@ -31,7 +25,7 @@ ul { } -li a { +nav li a { display: block; color: white; text-align: center; @@ -40,7 +34,7 @@ li a { } -li a:hover { +nav li a:hover { border-bottom-right-radius: 1000%; border-top-right-radius: 1000%; border-top-left-radius: -1000%; @@ -48,7 +42,7 @@ li a:hover { background-color: #111; } -li a:hover:last-child { +nav li a:hover:last-child { border-bottom-right-radius: 1000%; border-top-right-radius: 1000%; border-top-left-radius: 1000%; diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000000000000000000000000000000000000..9a1af7ec00074ae49b10865085a71494a7d8b8d3 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,18 @@ +{% extends "main.html" %} +{% block title %}Home{% endblock %} +{% block mainBlock %} +<ul> + {% for workspace in workspaces %} + <li><a href="{{ workspace.website }}">{{ workspace.name }}</a> + <img src="{{ workspace.main_photo }}"></li> + <ul> + <li>{{ workspace.address }}</li> + <li>{{ workspace.description }}</li> + <li>{{ workspace.email }}</li> + <li>{{ workspace.phone_number }}</li> + <li>{{ workspace.opening_hours }}</li> + <li>{{ workspace.checkin_instructions }}</li> + </ul> + {% endfor %} +</ul> +{% endblock %} \ No newline at end of file diff --git a/home.html b/templates/main.html similarity index 68% rename from home.html rename to templates/main.html index e8399080004118fe0ab514abd758068986f48cf2..34903741b4d4bcc011c8909b6474a4f16a9e6add 100644 --- a/home.html +++ b/templates/main.html @@ -1,9 +1,8 @@ <!DOCTYPE html> <html lang="en"> -<link rel="stylesheet" href="styles.css"> <head> - <link rel="stylesheet" href="style.css"> + <link rel="stylesheet" href="static/style.css"> <!-- Bootstrap CSS --> <link rel="stylesheet" href= @@ -12,12 +11,12 @@ "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> - <title>Hello</title> + <title>{% block title %}{% endblock %} - Tramshed Workspaces</title> </head> <div class="parallax"> <body class="body"> - <img src="Tramshed_Logo.jpg" alt="Logo" height="50" width="100"> + <img src="static/Tramshed_Logo.jpg" alt="Logo" height="50" width="100"> <!-- navigation --> <nav> <ul> @@ -26,4 +25,7 @@ <li><a href="#contactUs">Contact Us</a></li> <li style="float:right"><a class="active" href="#about">About</a></li> </ul> - </nav><br><br><br> + </nav> + {% block mainBlock %}{% endblock %} + </body> +</html>