Skip to content
Snippets Groups Projects
Commit fa10521c authored by Liam Driscoll's avatar Liam Driscoll
Browse files

Adding temporary server to test add record functions.

parent 3cc68dc8
No related branches found
No related tags found
3 merge requests!20Draft: resolving merge conflicts,!12locations.css,!10Adding files related to adding a coworking space.
File moved
from csv import writer from csv import writer
def addWorkingSpaces(values): def addCoworkingSpaces(data):
with open('coworking_spaces.csv', 'a') as addToFile: with open('coworking_spaces.csv', 'a') as addToFile:
csvWriter = writer(addToFile) csvWriter = writer(addToFile)
csvWriter.writerow(values) csvWriter.writerow(data)
addToFile.close() addToFile.close()
return (f"{values} added.") return (f"{data} added.")
<!DOCTYPE html>
<html lang="EN" dir="ltr">
<head>
<meta charSet="UTF-8">
<title> Page Template </title>
<link rel="stylesheet" href="StylingSheet.css">
</head>
<body onLoad="pageLoad()">
<header id="header">
<a href=""><h1>Page Header</h1></a>
</header>
<hr>
<main id="recordSection">
<form id="recordForm" title="Record Form">
<label>Name: <input name="record_name" id="recordName"
type="text"></label><br>
<label>Address: <input name="record_address" id="recordAddress"
type="text"></label><br>
<label>Main Photograph: <input name="record_MP" id="recordMainPhotos"
type="text"></label><br>
<label>Additional Photographs: <input name="record_AP" id="recordAdditionalPhotos"
type="text"></label><br>
<label>Description: <input name="record_description" id="recordDescription"
type="text"></label><br>
<label>Website: <input name="record_website" id="recordWebsite"
type="text"></label><br>
<label>Email: <input name="record_email" id="recordEmail"
type="text"></label><br>
<label>Phone Number: <input name="record_PN" id="recordPhoneNumber"
type="text"></label><br>
<label>Opening Hours: <input name="record_OH" id="recordOpeningHours"
type="text"></label><br>
<label>Checkin Instructions: <input name="record_CI" id="recordCheckinInstructions"
type="text"></label>
<br><br>
<button id="addButton" type="submit">Add</button>
</form>
<br>
<span id="DEBUGserverMessage"> </span>
</main>
<hr>
<footer id="footer">
<a href="#header">Top</a>
</footer>
<script src="Manage_Coworking_Spaces.js"></script>
</body>
</html>
// Replaces the onSubmit attribute for the addRecord form.
function pageLoad() {
document.getElementById('addButton').addEventListener('click',addRecord);
}
// Adds a record to the CSV file.
function addRecord(e) {
// Removes the standard form processing.
e.preventDefault();
e.stopPropagation();
var recordName = document.getElementById("recordName").value;
var recordAddress = document.getElementById("recordAddress").value;
var recordMainPhotos = document.getElementById("recordMainPhotos").value;
var recordAdditionalPhotos = document.getElementById("recordAdditionalPhotos").value;
var recordDescription = document.getElementById("recordDescription").value;
var recordWebsite = document.getElementById("recordWebsite").value;
var recordEmail = document.getElementById("recordEmail").value;
var recordPhoneNumber = document.getElementById("recordPhoneNumber").value;
var recordOpeningHours = document.getElementById("recordOpeningHours").value;
var recordCheckinInstructions = document.getElementById("recordCheckinInstructions").value;
var params = 'recordName='+recordName+'&recordAddress='+recordAddress+'&recordMainPhotos='+recordMainPhotos+'&recordAdditionalPhotos='+recordAdditionalPhotos+'&recordDescription='+recordDescription+'&recordWebsite='+recordWebsite+'&recordEmail='+recordEmail+'&recordPhoneNumber='+recordPhoneNumber+'&recordOpeningHours='+recordOpeningHours+'&recordCheckinInstructions='+recordCheckinInstructions;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", '/AddRecord', true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) {
console.log(xhttp.responseText);
document.getElementById("DEBUGserverMessage").innerHTML = xhttp.responseText;
} else {
console.error(`Status Text: ${xhttp.statusText}.`);
console.error(`Ready State: ${xhttp.readyState}.`);
}
};
xhttp.send(params);
}
File added
File added
File added
import os
from flask import Flask, redirect, request, render_template, jsonify
from static import Coworking_Functions
app = Flask(__name__)
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
@app.route("/AddRecord", methods=['POST'])
def addRecord():
print('Processing record.')
infoMessage = 'Add record failed.'
if (request.method == 'POST'):
recordName = request.form['recordName']
recordAddress = request.form['recordAddress']
recordMainPhotos = request.form['recordMainPhotos']
recordAdditionalPhotos = request.form['recordAdditionalPhotos']
recordDescription = request.form['recordDescription']
recordWebsite = request.form['recordWebsite']
recordEmail = request.form['recordEmail']
recordPhoneNumber = request.form['recordPhoneNumber']
recordOpeningHours = request.form['recordOpeningHours']
recordCheckinInstructions = request.form['recordCheckinInstructions']
recordData = [recordName, recordAddress, recordMainPhotos, recordAdditionalPhotos, recordDescription, recordWebsite, recordEmail, recordPhoneNumber, recordOpeningHours, recordCheckinInstructions]
Coworking_Functions.addCoworkingSpaces(recordData)
print(infoMessage)
return infoMessage
if __name__ == "__main__":
app.run(debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment