From 2029ef5aeb94e3da5ac98ef2a71c75b046eced39 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Sun, 11 Nov 2018 01:19:32 +0100 Subject: [PATCH] made location listing part of the template, rather than an unnecesary AJAX request + secret sauce sorting --- parts/server.py | 14 +++++--------- parts/static/script.js | 5 ----- parts/templates/partsearch.html | 8 +++++++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/parts/server.py b/parts/server.py index 1cf7ed4..c0fc844 100644 --- a/parts/server.py +++ b/parts/server.py @@ -47,17 +47,13 @@ def serveImage(img): @app.route('/parts') def index(): - return render_template('partsearch.html') - -@app.route('/parts/getlocations/') -def get_locations(): - s = 'select id, name from locations order by name;' - r = db_engine.execute(text(s)) - l = {} + query = "select id, name from locations order by left(map, strpos(map, '.')-1), UPPER(name);" + r = db_engine.execute(text(query)) + locations = [] for row in r: - l[row[0]]=row[1] + locations.append(dict(row)) r.close() - return json.dumps(l) + return render_template('partsearch.html', locations=locations) @app.route('/parts/getlocationURL/') def get_locationURL(locationID): diff --git a/parts/static/script.js b/parts/static/script.js index acdcc28..0a1c71a 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -225,11 +225,6 @@ function update_map() { } $(document).ready(function() { - $.getJSON('parts/getlocations', function(data){ - $.each(data, function(i, val) { - $('table#details tr#location td select').append(''); - }); - }); $.ajaxSetup({ cache: false }); $('.search-bar').on('keyup', function() { perform_query(); diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index b275ef2..9a9a117 100644 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -43,7 +43,13 @@

Part Details

- +
LOCATION

+ +
PART NUMBER

DESCRIPTION