From 17e0d560cce99f8d806e65aa2cfa57f28a86da52 Mon Sep 17 00:00:00 2001 From: Billy Date: Mon, 29 Apr 2024 14:40:03 -0400 Subject: [PATCH] Created the pages for viewing and adding data --- app.py | 43 +++++++++++++- generate_data.py | 4 +- templates/add.js | 3 + templates/adding.html | 71 +++++++++++++++++++++++ templates/main.html | 129 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 232 insertions(+), 18 deletions(-) create mode 100644 templates/add.js create mode 100644 templates/adding.html diff --git a/app.py b/app.py index 4289658..6f3735d 100644 --- a/app.py +++ b/app.py @@ -5,11 +5,52 @@ app = Flask(__name__) connection = sql_utils.connect_database('ubuntu-mariadb.home','admin','password','inventory') + +@app.route('/user_search') +def user_search(): + data = request.args.get('data') + query = f''' +SELECT u.name,u.id_num,u.assigned_asset,u.assigned_card +FROM users u +WHERE u.name like '%{data.upper()}%\'''' + response = sql_utils.read_query(connection, query) + print(response) + return response + +@app.route('/asset_tag_search') +def asset_tag_search(): + data = request.args.get('data') + query = f'''SELECT a.asset_id, a.serial, a.model, a.category, u.name +FROM assets a +left JOIN users u ON u.assigned_asset=a.asset_id +WHERE a.asset_id = {data.upper()}''' + response = sql_utils.read_query(connection, query) + return response + +@app.route('/serial_search') +def serial_search(): + data = request.args.get('data') + query = f'''SELECT a.asset_id, a.serial, a.model, a.category, u.name +FROM assets a +left JOIN users u ON u.assigned_asset=a.asset_id +WHERE a.serial LIKE "{data.upper()}"''' + response = sql_utils.read_query(connection, query) + return response + @app.route('/asset_list') def asset_list(): - data = sql_utils.read_query(connection,'select * from assets;') + query = ''' +select a.asset_id,a.serial,a.model,a.category,u.name +from assets a +left join users u on u.assigned_asset=a.asset_id +''' + data = sql_utils.read_query(connection,query) return data +@app.route('/add') +def add_data(): + return render_template('adding.html') + @app.route("/") def default(): return render_template('main.html') diff --git a/generate_data.py b/generate_data.py index 4e9b39d..b4548e9 100644 --- a/generate_data.py +++ b/generate_data.py @@ -9,4 +9,6 @@ for i in range(0,100): serial = "".join(random.choices(alphabet, k=12)) query = f'insert into assets (serial) values ("{serial}")' sql_utils.send_query(connection, query) - print(f'Inserting: {serial}') \ No newline at end of file + print(f'Inserting: {serial}') + +print("test") \ No newline at end of file diff --git a/templates/add.js b/templates/add.js new file mode 100644 index 0000000..e24b816 --- /dev/null +++ b/templates/add.js @@ -0,0 +1,3 @@ +function update_add_asset_model() { + +} \ No newline at end of file diff --git a/templates/adding.html b/templates/adding.html new file mode 100644 index 0000000..5ef137d --- /dev/null +++ b/templates/adding.html @@ -0,0 +1,71 @@ + + + + + + + Adding + + + + + +
+

Add asset

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+

Add user

+
+
+

Add access card

+
+
+

Modify asset

+
+
+

Modify user

+
+
+

Modify access card

+
+ + + + + + \ No newline at end of file diff --git a/templates/main.html b/templates/main.html index a1fbc4f..b291dc9 100644 --- a/templates/main.html +++ b/templates/main.html @@ -4,36 +4,133 @@ - Document + Searching -

Assets

- - - - - - - -
Asset tagSerial NumberModelCategory
- +
+

Assets

+ + + + + + + + +
Asset tagSerial NumberModelCategoryAssigned to
+
+
+

User info search

+ + + + +

results

+ + + + + + + +
NameID numberAssigned assetAssigned card
+
+
+

Asset number search

+ + + + +

results

+
+

use the search box above to get results

+
+
+ +