Skip to content
Snippets Groups Projects
Verified Commit 6cc1976f authored by Robert Metcalf's avatar Robert Metcalf
Browse files

add page to add workspaces

parent 2bde9431
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
......@@ -85,6 +85,31 @@ class Workspace:
self.opening_hours = opening_hours
self.checkin_instructions = checkin_instructions
def validate(self):
errors = []
if len(self.name.strip()) <= 0:
errors.append("Name must not be empty")
if len(self.address.strip()) <= 0:
errors.append("Address must not be empty")
if len(self.main_photo.strip()) <= 0:
errors.append("Main photo must not be empty")
if len(self.description.strip()) <= 0:
errors.append("Description must not be empty")
if len(self.website.strip()) <= 0:
errors.append("Website must not be empty")
if len(self.email.strip()) <= 0:
errors.append("Email must not be empty")
if len(self.phone_number.strip()) <= 0:
errors.append("Phone number must not be empty")
if len(self.opening_hours.strip()) <= 0:
errors.append("Opening hours must not be empty")
for x in self.additional_photos:
if len(x.strip()) <= 0:
errors.append("Each edditional photos must not be empty")
return errors
def from_query(conn, tuple):
(id, name, address, main_photo, description, website, email, phone_number, opening_hours, checkin_instructions) = tuple
additional_photos = []
......
......@@ -19,5 +19,46 @@ def map():
dumped = json.dumps(data)
return render_template("map.html", json = re.sub(r"(?i)\</script\>", "<\/script>", dumped)) # escape </script>
@app.route("/admin/add-workspace", methods = ["GET", "POST"])
def add_workspace():
if request.method == "GET":
return render_template("add-workspace.html")
if request.method == "POST":
additional_photos = request.form["additional_photos"]
additional_photos = [x.strip() for x in additional_photos.split("\n")] if len(additional_photos) > 0 else []
workspace = database.Workspace(
request.form["name"],
request.form["address"],
request.form["main_photo"],
additional_photos,
request.form["description"],
request.form["website"],
request.form["email"],
request.form["phone_number"],
request.form["opening_hours"],
request.form["checkin_instructions"]
)
errors = workspace.validate()
try:
latitude = float(request.form["latitude"])
except ValueError:
errors.append("Latitude must be a number")
try:
longitude = float(request.form["longitude"])
except ValueError:
errors.append("Longitude must be a number")
if len(errors) > 0:
messages = ["Errors were found:"]
messages.extend(errors)
else:
database.set_address_latlong(workspace.address, (latitude, longitude))
database.add_workspace(workspace)
messages = ["Workspace added successfully"]
return render_template("add-workspace-result.html", messages = messages)
if __name__ == "__main__":
app.run(debug = True)
{% extends "main.html" %}
{% block title %}Add Workspace{% endblock %}
{% block mainBlock %}
{% for message in messages %}
<div>{{ message }}</div>
{% endfor %}
{% endblock %}
\ No newline at end of file
{% extends "main.html" %}
{% block title %}Add Workspace{% endblock %}
{% block mainBlock %}
<form action="/admin/add-workspace" method="POST">
<div>
<label for="name">Name:</label>
<input id="name" type="text" name="name">
</div>
<div>
<label for="name">Address:</label>
<input id="address" type="text" name="address">
</div>
<div>
<label for="main-photo">Main Photo:</label>
<input id="main-photo" type="text" name="main_photo">
</div>
<div>
<label for="additional-photos">Additional Photos:</label>
<div><textarea id="additional-photos" name="additional_photos"></textarea></div>
</div>
<div>
<label for="description">Description:</label>
<div><textarea id="description" name="description"></textarea></div>
</div>
<div>
<label for="website">Website:</label>
<input id="website" type="text" name="website">
</div>
<div>
<label for="email">Email:</label>
<input id="email" type="text" name="email">
</div>
<div>
<label for="phone-number">Phone Number:</label>
<input id="phone-number" type="text" name="phone_number">
</div>
<div>
<label for="opening-hours">Opening Hours:</label>
<input id="opening-hours" type="text" name="opening_hours">
</div>
<div>
<label for="checkin-instructions">Checkin Instructions:</label>
<div><textarea id="checkin-instructions" name="checkin_instructions"></textarea></div>
</div>
<div>
<label for="latitude">Latitude:</label>
<input id="latitude" type="text" name="latitude">
</div>
<div>
<label for="longitude">Longitude:</label>
<input id="longitude" type="text" name="longitude">
</div>
<div>
<input type="submit">
</div>
</form>
{% endblock %}
\ No newline at end of file
......@@ -9,14 +9,14 @@
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet" href="static/style.css">
<link rel="stylesheet" href="/static/style.css">
<title>{% block title %}{% endblock %} - Tramshed Workspaces</title>
</head>
<div class="parallax">
<body class="body">
<img src="static/Tramshed_Logo.jpg" alt="Logo" height="50" width="100">
<img src="/static/Tramshed_Logo.jpg" alt="Logo" height="50" width="100">
<!-- navigation -->
<nav>
<ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment