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

Changes to search functionality.

parent 4a65e732
No related branches found
No related tags found
1 merge request!43Changes to search functionality.
...@@ -10,29 +10,31 @@ ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) ...@@ -10,29 +10,31 @@ ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
@app.route("/", methods=['GET']) @app.route("/", methods=['GET'])
def returnIndex(): def returnIndex():
return render_template("test.html") if (request.method == 'GET'):
return render_template("test.html")
@app.route("/Manage_Coworking_Spaces", methods=['GET']) @app.route("/Manage_Coworking_Spaces", methods=['GET'])
def returnManageCoworkingSpaces(): def returnManageCoworkingSpaces():
return render_template("Manage_Coworking_Spaces.html") if (request.method == 'GET'):
return render_template("Manage_Coworking_Spaces.html")
@app.route("/SearchRecord", methods=['POST']) @app.route("/SearchRecord", methods=['POST', 'GET'])
def searchRecord(): def searchRecord():
if request.method =='POST': try:
try: recordName = request.form.get('recordName', default="Error")
recordName = request.form.get('recordName', default="Error") conn = sqlite3.connect(DATABASE)
conn = sqlite3.connect(DATABASE) cur = conn.cursor()
cur = conn.cursor() cur.execute("SELECT * FROM coworking_spaces WHERE Name=?;", [recordName])
cur.execute("SELECT * FROM coworking_spaces WHERE Name=?;", [recordName]) recordData = cur.fetchall()
recordData = cur.fetchall()
except: except:
print(f"Error: {recordData}") print(f"Error: {recordData}")
conn.close() conn.close()
finally: finally:
conn.close() conn.close()
print(f"{str(recordData)} Record found.") print(f"{recordData} Record found.")
return str(recordData) return (recordData)
# Adds a record to the CSV file. # Adds a record to the CSV file.
@app.route("/AddRecord", methods=['POST']) @app.route("/AddRecord", methods=['POST'])
......
...@@ -52,6 +52,17 @@ function searchRecord(e) { ...@@ -52,6 +52,17 @@ function searchRecord(e) {
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) { if (xhttp.readyState === 4 && xhttp.status === 200) {
console.log(xhttp.responseText); console.log(xhttp.responseText);
serverResponse = JSON.parse(xhttp.responseText);
document.getElementById("recordName").value = serverResponse[0][0];
document.getElementById("recordAddress").value = serverResponse[0][1];
document.getElementById("recordMainPhotos").value = serverResponse[0][2];
document.getElementById("recordAdditionalPhotos").value = serverResponse[0][3];
document.getElementById("recordDescription").value = serverResponse[0][4];
document.getElementById("recordWebsite").value = serverResponse[0][5];
document.getElementById("recordEmail").value = serverResponse[0][6];
document.getElementById("recordPhoneNumber").value = serverResponse[0][7];
document.getElementById("recordOpeningHours").value = serverResponse[0][8];
document.getElementById("recordCheckinInstructions").value = serverResponse[0][9];
document.getElementById("DEBUGserverMessage").innerHTML = xhttp.responseText; document.getElementById("DEBUGserverMessage").innerHTML = xhttp.responseText;
} else { } else {
console.error(`Status Text: ${xhttp.statusText}.`); console.error(`Status Text: ${xhttp.statusText}.`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment