|
|
@ -1,6 +1,7 @@
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import sqlalchemy
|
|
|
|
import sqlalchemy
|
|
|
|
from sqlalchemy.sql import select
|
|
|
|
from sqlalchemy.sql import select
|
|
|
|
|
|
|
|
from sqlalchemy.sql import text
|
|
|
|
from flask import Flask
|
|
|
|
from flask import Flask
|
|
|
|
from flask import render_template
|
|
|
|
from flask import render_template
|
|
|
|
|
|
|
|
|
|
|
@ -14,9 +15,28 @@ parts = {}
|
|
|
|
def index():
|
|
|
|
def index():
|
|
|
|
return render_template('partsearch.html')
|
|
|
|
return render_template('partsearch.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/query/<query>')
|
|
|
|
@app.route('/query/<filter>/<query>')
|
|
|
|
def query(query):
|
|
|
|
def query(filter, query):
|
|
|
|
pass
|
|
|
|
query = '%' + query + '%'
|
|
|
|
|
|
|
|
s = 'select * from parts where '
|
|
|
|
|
|
|
|
if filter & (1 << 0) != 0:
|
|
|
|
|
|
|
|
s += 'type like :name or '
|
|
|
|
|
|
|
|
if filter & (1 << 1) != 0:
|
|
|
|
|
|
|
|
s += 'partno like :name or '
|
|
|
|
|
|
|
|
if filter & (1 << 2) != 0:
|
|
|
|
|
|
|
|
s += 'partnoalt like :name or '
|
|
|
|
|
|
|
|
if filter & (1 << 3) != 0:
|
|
|
|
|
|
|
|
s += 'partnoalt2 like :name or '
|
|
|
|
|
|
|
|
if filter & (1 << 4) != 0:
|
|
|
|
|
|
|
|
s += 'description like :name or '
|
|
|
|
|
|
|
|
s = s[:-4] + ';'
|
|
|
|
|
|
|
|
s = text(s)
|
|
|
|
|
|
|
|
r = db_engine.execute(s, name=query)
|
|
|
|
|
|
|
|
l = []
|
|
|
|
|
|
|
|
for row in r:
|
|
|
|
|
|
|
|
l.append(dict(row))
|
|
|
|
|
|
|
|
r.close()
|
|
|
|
|
|
|
|
return json.dumps(l)
|
|
|
|
|
|
|
|
|
|
|
|
def connect(user, password, db, host='localhost', port=5432):
|
|
|
|
def connect(user, password, db, host='localhost', port=5432):
|
|
|
|
'''Returns a connection and a metadata object'''
|
|
|
|
'''Returns a connection and a metadata object'''
|
|
|
|