From fe97bb098b4b05756ef452182a53fe62fb5cd59b Mon Sep 17 00:00:00 2001 From: Daniel Rahamim Date: Sun, 25 Dec 2022 18:30:15 -0800 Subject: [PATCH] fix: typo in existing checkout (#6) * fix: typo in existing checkout alert based on suggestion from @jayreed-nava * ci: remove un-needed python 3.0 lint check * ci: typo in lint python version * ci: add flake8 ignore rule e501 * chore: fix lint in init_db.py --- .github/workflows/lint.yml | 11 +++---- app.py | 57 ++++++++++++++++++++++++------------- database.db | Bin 40960 -> 40960 bytes init_db.py | 4 +-- schema.sql | 2 +- 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 350e09f..2caf8e4 100755 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,19 +8,16 @@ on: jobs: code_lint: runs-on: ubuntu-latest - strategy: - matrix: - # Run in all these versions of Python - python-version: [3.9, '3.10'] + steps: # Checkout the latest code from the repo - name: Checkout repo uses: actions/checkout@v3 # Setup which version of Python to use - - name: Set Up Python ${{ matrix.python-version }} + - name: Set Up Python 3.10 uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: '3.10' # Display the Python version being used - name: Display Python version run: python -c "import sys; print(sys.version)" @@ -37,7 +34,7 @@ jobs: use-isort: false extra-pylint-options: "" extra-pycodestyle-options: "" - extra-flake8-options: "" + extra-flake8-options: "--ignore=E501" extra-black-options: "" extra-mypy-options: "" extra-isort-options: "" diff --git a/app.py b/app.py index 03b9f5e..689e74e 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ import sqlite3 -from flask import Flask, render_template, request, url_for, flash, redirect, abort +from flask import Flask +from flask import render_template, request, url_for, flash, redirect, abort app = Flask(__name__) @@ -50,9 +51,11 @@ def index(): assets = conn.execute('SELECT * FROM assets').fetchall() asset_total = conn.execute('SELECT COUNT(*) FROM assets').fetchone()[0] asset_types = conn.execute( - 'SELECT asset_type, COUNT(*) FROM assets GROUP BY asset_type').fetchall() + 'SELECT asset_type, COUNT(*) FROM assets GROUP BY asset_type' + ).fetchall() asset_status = conn.execute( - 'SELECT asset_status, COUNT(*) FROM assets GROUP BY asset_status').fetchall() + 'SELECT asset_status, COUNT(*) FROM assets GROUP BY asset_status' + ).fetchall() conn.close() return render_template( 'index.html', assets=assets, asset_total=asset_total, @@ -73,8 +76,10 @@ def create_asset(): else: try: conn = get_db_connection() - conn.execute('INSERT INTO assets (id, asset_type, asset_status) VALUES (?, ?, ?)', - (id, asset_type, asset_status)) + conn.execute( + 'INSERT INTO assets (id, asset_type, asset_status)' + 'VALUES (?, ?, ?)', + (id, asset_type, asset_status)) conn.commit() conn.close() return redirect(url_for('status')) @@ -114,7 +119,7 @@ def edit_asset(id): def delete(id): asset = get_asset(id, "edit") conn = get_db_connection() - conn.execute('DELETE FROM assets WHERE id = ?', (id,)) + conn.execute('DELETE FROM assets WHERE id = ?', (asset,)) conn.commit() conn.close() flash('Asset "{}" was successfully deleted!'.format(id)) @@ -149,29 +154,36 @@ def checkout(): flash("Asset does not exist. Please make it below") return redirect(url_for('create_asset')) elif get_asset(asset_id, 'edit')['asset_status'] == 'damaged': - flash("Asset should not be checked ou. Please choose another one") + flash("Asset should not be checked out. Please choose another one") return redirect(url_for('checkout')) else: staff_dept = get_staff(staff_id)['Department'] flash(get_asset(asset_id, 'edit')['asset_status']) try: conn = get_db_connection() - conn.execute('INSERT INTO checkouts (assetid, staffid, department) VALUES (?, ?, ?)', - (asset_id, staff_id, staff_dept)) - conn.execute('UPDATE assets SET asset_status = "checkedout" WHERE id = ?', - (asset_id,)) + conn.execute( + 'INSERT INTO checkouts (assetid, staffid, department) ' + 'VALUES (?, ?, ?)', (asset_id, staff_id, staff_dept)) + conn.execute('UPDATE assets SET asset_status = "checkedout" ' + 'WHERE id = ?', (asset_id,)) if accessory_id: - conn.execute('INSERT INTO checkouts (assetid, staffid, department) VALUES (?, ?, ?)', - (accessory_id, staff_id, staff_dept)) - conn.execute('UPDATE assets SET asset_status = "checkedout" WHERE id = ?', - (accessory_id,)) + conn.execute( + 'INSERT INTO checkouts (assetid, staffid, department)' + ' VALUES (?, ?, ?)', + (accessory_id, staff_id, staff_dept)) + conn.execute( + 'UPDATE assets SET asset_status = "checkedout" ' + 'WHERE id = ?', + (accessory_id,)) conn.commit() conn.close() flash('Asset Checkout Completed') return redirect(url_for('checkout')) except sqlite3.IntegrityError: - flash("Asset already checked out! Please check-in before checking out") + flash( + "Asset already checked out! Please check-in " + "before checking out") return redirect(url_for('checkout')) return render_template('checkout.html') @@ -190,16 +202,21 @@ def checkin(): staff_div = get_staff(asset_checkout['staffid'])['Division'] try: conn = get_db_connection() - conn.execute('INSERT INTO history (assetid, staffid, department, division, checkouttime) VALUES (?,?,?,?,?)', - (asset_id, asset_checkout['staffid'], asset_checkout['department'], staff_div, asset_checkout['timestamp'])) + conn.execute( + 'INSERT INTO history (assetid, staffid, department, division, checkouttime) VALUES (?,?,?,?,?)', + (asset_id, asset_checkout['staffid'], + asset_checkout['department'], staff_div, + asset_checkout['timestamp'])) conn.execute( 'DELETE from checkouts WHERE assetid = ?', (asset_id,)) if get_asset(asset_id, "edit")['asset_status'] == "damaged": conn.execute( - 'UPDATE assets SET asset_status = ? WHERE id = ?', ('damaged', asset_id)) + 'UPDATE assets SET asset_status = ? WHERE id = ?', + ('damaged', asset_id)) else: conn.execute( - 'UPDATE assets SET asset_status = ? WHERE id = ?', ('Available', asset_id)) + 'UPDATE assets SET asset_status = ? WHERE id = ?', + ('Available', asset_id)) conn.commit() conn.close() flash('Asset checkin Completed') diff --git a/database.db b/database.db index ff0f33dc47aed8d962c4aae8b0d9f691f146fb92..10a9e3401a7042f337c525c1bdb9f12cc1e8c298 100644 GIT binary patch delta 367 zcmZoTz|?SnX@az19RmXc7ZAfh>_i=7={g3zWCmWK5Igq`2L48VE50<|CA@w-!Q3}C zHpX#J{={9wS;59GE-lU2>^`}i=i+2HK84MGyzESj%#*|TS91fkGVz~b;D5${X0xEd z0e%w+CKho?`63e|6QkVxq|BUD$FjuCoW!J@R0&3~jIoh1R3;H7v&rBSKOaa369=<6 zXAwxnA_W0HR-oaG{J%jCX5s(6S+L+e|Kz{^>}(7I3=I6&f!1B%H_#N6H3nN|Y#LBn znxWvGT4`ipWTb0oq-$iRU|?irWN2k#0QNUX*LScff()EsJs^)W@*iN}KL9jr8^41c ZBfGeute`QviKYfv%)}5fHD1)9007F1+nQWCmWK5IgrL2L48VE50<|CA@w-x!j*N z3kp