From fa10521c5b156bdc558059b0293993b5d42a1afb Mon Sep 17 00:00:00 2001 From: Liam Driscoll <driscolll4@cardiff.ac.uk> Date: Thu, 24 Nov 2022 22:34:16 +0000 Subject: [PATCH] Adding temporary server to test add record functions. --- __init__.py | 0 ...working_spaces.csv => coworking_spaces.csv | 0 ...es_functions.py => Coworking_Functions.py} | 6 +- static/Manage_Coworking_Spaces.html | 55 ++++++++++++++++++ static/Manage_Coworking_Spaces.js | 38 ++++++++++++ static/__init__.py | 0 static/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 200 bytes .../coworking_functions.cpython-310.pyc | Bin 0 -> 530 bytes ...coworking_spaces_functions.cpython-310.pyc | Bin 0 -> 535 bytes tempServer.py | 34 +++++++++++ 10 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 __init__.py rename static/coworking_spaces.csv => coworking_spaces.csv (100%) rename static/{coworking_spaces_functions.py => Coworking_Functions.py} (59%) create mode 100644 static/Manage_Coworking_Spaces.html create mode 100644 static/Manage_Coworking_Spaces.js create mode 100644 static/__init__.py create mode 100644 static/__pycache__/__init__.cpython-310.pyc create mode 100644 static/__pycache__/coworking_functions.cpython-310.pyc create mode 100644 static/__pycache__/coworking_spaces_functions.cpython-310.pyc create mode 100644 tempServer.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/static/coworking_spaces.csv b/coworking_spaces.csv similarity index 100% rename from static/coworking_spaces.csv rename to coworking_spaces.csv diff --git a/static/coworking_spaces_functions.py b/static/Coworking_Functions.py similarity index 59% rename from static/coworking_spaces_functions.py rename to static/Coworking_Functions.py index 362635f..a5c9134 100644 --- a/static/coworking_spaces_functions.py +++ b/static/Coworking_Functions.py @@ -1,9 +1,9 @@ from csv import writer -def addWorkingSpaces(values): +def addCoworkingSpaces(data): with open('coworking_spaces.csv', 'a') as addToFile: csvWriter = writer(addToFile) - csvWriter.writerow(values) + csvWriter.writerow(data) addToFile.close() - return (f"{values} added.") + return (f"{data} added.") diff --git a/static/Manage_Coworking_Spaces.html b/static/Manage_Coworking_Spaces.html new file mode 100644 index 0000000..7f11000 --- /dev/null +++ b/static/Manage_Coworking_Spaces.html @@ -0,0 +1,55 @@ +<!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> diff --git a/static/Manage_Coworking_Spaces.js b/static/Manage_Coworking_Spaces.js new file mode 100644 index 0000000..2cd7b3f --- /dev/null +++ b/static/Manage_Coworking_Spaces.js @@ -0,0 +1,38 @@ +// 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); +} diff --git a/static/__init__.py b/static/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/static/__pycache__/__init__.cpython-310.pyc b/static/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2e099c12ae40d9f36336371daeaa85bcd52de30f GIT binary patch literal 200 zcmd1j<>g`k0t>ImWDxxrL?8o3AjbiSi&=m~3PUi1CZpd<h9ZzKg7}r~WEB&foROcO z6XTp%l#-d2rVyH!S(aK<oLN#C6PcP=q+l46oRgWFSE5@`l%JKFTv8lUQk0lmoRONM zTaucbp^GXD6idw2H8hPWE=erOOpb|<&&<m#iI3MSsJz8tlbfGXnv-e=azrr`kYHf| E03Y@={{R30 literal 0 HcmV?d00001 diff --git a/static/__pycache__/coworking_functions.cpython-310.pyc b/static/__pycache__/coworking_functions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..686c5e64725d8003e480164cad09f9b2c489d099 GIT binary patch literal 530 zcmY*WKTiTN6mNTn90V5QV4R3?xd9Re7h{Z(#F0TXgv%wSX^T{kD`^V^0&&3I4`57S z^s_j--0I|4FbuvsHR5}D@8$jJukY8Ya=C~=Uf=H78sdAJYzl$o6wK^`<A~!3^>KhP z;)FX7C?MQzAwTy4UF73rYpkUen&CA65eK3N)&MgX;4Hv!vLKIpb8PVpFYuhq$db&^ z3V>&L>8ub$^n|$cOxlRR#V+W=!Kj7m$n1|{F4Ybghnnv;r#noImA;el&9xa&CQOZ) zQG)3-U!j}}Ui00=RRa<0lvCh+Z>q*gjz!7{-$`6fEe#4VeW}i6B!U7Uv@=34Nax|y z=jiMxY_XnFQP`lG%Wk)F70Z#(M%qc(5mZ;|A&aDlZFQj4tzg!KR@1)e30}2=^{W57 zP^0~7{V+6^TFJsc65V0UtW>e74JOGpEY<ks*UIRn&uU8GO2orO?13JvbpZ-Z-w7O8 dJtLY`vgJ2i`W=aP+*f=UiIeoRjGH0>))&E$g%|(; literal 0 HcmV?d00001 diff --git a/static/__pycache__/coworking_spaces_functions.cpython-310.pyc b/static/__pycache__/coworking_spaces_functions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..97f919c253eb91632b309dafbbf07caa64c515c3 GIT binary patch literal 535 zcmZ8ePfG$p6rY)0a}|XS9io#&mpv$W=n@f8(9uH{;<6ya%$QT_j?9dTqI9r(A0Prf z_GS72d+pR$kb>T>9jy0w@A3Z3Z{BZ4mCHp0^8NnE)(}6^WLpR%=U`?Z97h~SsE-4T z5hvVvLIL4!6ZyGM=pr8{J7X=a&<v;fuQ(7ruuCv=4bB1#Ckyg?Fvk|p@B+`tj4a6v ztpIq2m(B`7L@$UtucU<tT<n4_9E_T%j?Cd0=2C5gaj5xjW4g!GSm_5D-*wD@GGS`W zj1o+z`3mJ+@S5)?t{R9~r<?+Bv#A;<ITk4+d?#@^wKOQe^o_cbkq8Qa(8>tCA)SX) z>-oh=*knDWqVSSxF1y{zZ7fGZ8)+wDTTor8hb)pJw$*`F_kvjyT21?=CwSEg)~o*Q zLXGyT_2bZ3Y9$N*ljwAZF|$&|rZ$))yRchpL$aB1OyAa&z?F!Hi`WA_`qBj`G<+v; eVE>G5R>>G_x%5vG@3gP@FcN3!j~O>b0<0f1HHT6F literal 0 HcmV?d00001 diff --git a/tempServer.py b/tempServer.py new file mode 100644 index 0000000..bd1f86d --- /dev/null +++ b/tempServer.py @@ -0,0 +1,34 @@ +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) -- GitLab