Skip to content

Commit

Permalink
fix: typo in existing checkout (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
drahamim authored Dec 26, 2022
1 parent 25f1f71 commit fe97bb0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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: ""
Expand Down
57 changes: 37 additions & 20 deletions app.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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,
Expand All @@ -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'))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')

Expand All @@ -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')
Expand Down
Binary file modified database.db
Binary file not shown.
4 changes: 2 additions & 2 deletions init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

with open('schema.sql') as f:
connection.executescript(f.read())

connection.commit()
connection.close()
connection.close()
2 changes: 1 addition & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CREATE TABLE history(
department text NOT NULL,
division text NOT NULL,
checkouttime timestamp NOT NULL,
returntime timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
returntime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);


Expand Down

0 comments on commit fe97bb0

Please sign in to comment.