Skip to content

Commit

Permalink
Revert "20 bulk import staff (#22)" (#24)
Browse files Browse the repository at this point in the history
This reverts commit 0463c26.
  • Loading branch information
drahamim authored Feb 17, 2023
1 parent 0463c26 commit 7c9ebd4
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 184 deletions.
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,18 @@ Within the unpacked directory:

For development, perform an _editable install_ instead at step 2 above, with `pip install -e .`

## Import Staff
This can be done on the **Bulk Import** page.
## import staff
This will require a CSV formatted file
Fields in order

Staff information support the following columns of information:
```id, FirstName, LastName, Division, Department, Title```

```ID, First Name, Last Name, Division, Department, Title```
*ID must be unique*
Do not include a header row

Currently we do not support less than 6 columns on the import.
If you don't have all the matching just create blank columns with the headers as needed.

## Import Assets
This can be done on teh **Bulk Import** page.

Assets currently support the following columns:

```ID, Model, Status```
*ID must be unique*

Status is special because by default it will import as **Available** unless a column is specified for unique status tracking
```
sqlite3 database.db
sqlite> .mode csv
sqlite> .import ./test_data/<your staff file>.csv staffs
# verify it worked
sqlite> SELECT * from staffs;
```
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ requires-python = ">=3.10"

dependencies = [
"flask >=2.2.2, <3",
"toml >=0.10.2, <1",
"pandas==1.5.3"

"toml >=0.10.2, <1"
]

[project.scripts]
Expand Down
82 changes: 21 additions & 61 deletions src/invenflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def history():
return render_template('history.html', assets=assets)


@app.route('/bulk_import', methods=('GET', 'POST'))
def bulk_import():
@app.route('/bulk_asset', methods=('GET', 'POST'))
def bulk_asset():
if request.method == 'POST':
uploaded_file = request.files.get('file')
print(uploaded_file)
Expand All @@ -280,11 +280,9 @@ def bulk_import():
uploaded_file.save(os.path.join(
app.config['upload_folder'], data_filename))
session['uploaded_data_file_path'] = file_path
form_type = request.form['select_type']

return redirect(url_for('showData', form_type=form_type))
return redirect(url_for('showData'))
if request.method == "GET":
return render_template('bulk_import.html')
return render_template('bulk_assets.html')


@app.route('/show_data', methods=["GET", "POST"])
Expand All @@ -299,47 +297,30 @@ def showData():
uploaded_df_html = uploaded_df.to_html()
if request.method == "GET":
headers = pd.read_csv(data_file_path, nrows=1).columns.tolist()
form_type = request.args.get('form_type')

return render_template(
'bulk_import_verify.html', data_var=uploaded_df_html,
headers_list=headers, form_type=form_type)
'bulk_create_verify.html', data_var=uploaded_df_html,
headers_list=headers)
if request.method == "POST":
form_type = request.args.get('form_type')
if form_type == 'assets':
asset_id_field = request.form['asset_id']
asset_type_field = request.form['asset_type']
asset_status_field = request.form['asset_status']

parseCSV_assets(
data_file_path, asset_id_field,
asset_type_field, asset_status_field)
return redirect(url_for('status'))
elif form_type == 'staff':
first_name = request.form['first_name']
last_name = request.form['last_name']
staff_id = request.form['staff_id']
division = request.form['division']
department = request.form['department']
title = request.form['title']
parseCSV_staff(
data_file_path, first_name, last_name, staff_id,
division, department, title)

return redirect(url_for('staff'))
# First Name Last Name Staff ID Division Department Title


def parseCSV_assets(filePath, asset_id, asset_type, asset_status):
asset_id_field = request.form['asset_id']
asset_type_field = request.form['asset_type']
asset_status_field = request.form['asset_status']

parseCSV(
data_file_path, asset_id_field,
asset_type_field, asset_status_field)
return redirect(url_for('status'))


def parseCSV(filePath, asset_id, asset_type, asset_status):
# CVS Column Names
col_names = ['Model', 'FA_Number']
# Use Pandas to parse the CSV file
csvData = pd.read_csv(filePath, header=0)
csvData = pd.read_csv(filePath, names=col_names, header=1)
# Loop through the Rows

print("PARSING DATA")
print(asset_status)
for i, row in csvData.iterrows():
if asset_status != 'Available':
asset_status == row[asset_status]

try:
conn = get_db()
conn.execute(
Expand All @@ -352,24 +333,3 @@ def parseCSV_assets(filePath, asset_id, asset_type, asset_status):
flash("Asset upload failed import")
return redirect(url_for('create_asset'))
return redirect(url_for('status'))


def parseCSV_staff(
filePath, first_name, last_name, staff_id, division, department, title):
# Use Pandas to parse the CSV file
csvData = pd.read_csv(filePath, header=0)
# Loop through the Rows

for i, row in csvData.iterrows():
try:
conn = get_db()
conn.execute(
'INSERT INTO staffs (id, first_name, last_name, division, department, title)'
'VALUES(?,?,?,?,?,?)',
(row[staff_id], row[first_name], row[last_name],
row[division], row[department], row[title]))
conn.commit()
except sqlite3.IntegrityError:
flash("Asset upload failed import")
return redirect(url_for('create_asset'))
return redirect(url_for('status'))
10 changes: 5 additions & 5 deletions src/invenflask/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ CREATE UNIQUE INDEX asset_id on assets (id);

CREATE TABLE staffs(
id text NOT NULL,
first_name text NOT NULL,
last_name text NOT NULL,
division text NOT NULL,
department text NOT NULL,
title text NOT NULL
FirstName text NOT NULL,
LastName text NOT NULL,
Division text NOT NULL,
Department text NOT NULL,
Title text NOT NULL
);


Expand Down
4 changes: 2 additions & 2 deletions src/invenflask/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %} {% endblock %}AssetCheckout</title>
<title>{% block title %} {% endblock %}- AssetCheckout</title>
<style>
nav a {
color: #d64161;
Expand Down Expand Up @@ -33,7 +33,7 @@
<a href="{{ url_for('status') }}">Asset Status</a>
<a href="{{ url_for('history') }}">History</a>
<a href="{{ url_for('staff') }}">Staff</a>
<a href="{{ url_for('bulk_import') }}">Bulk Import</a>
<a href="{{ url_for('bulk_asset') }}">Bulk Asset</a>
<!-- <a href="{{ url_for('status') }}">Asset Status</a>
<a href="{{ url_for('status') }}">Asset Status</a>
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
{% block content %}
<h1>{% block title %} Bulk Asset Create {% endblock %}</h1>
<form method=post enctype=multipart/form-data>
<label>Select CSV data type:</label>
<select name="select_type",id="select_type">
<option value="assets">Assets</option>
<option value="staff">Staff</option>
</select>
<p><input type=file name=file></p>
<p><input type=submit value=Submit></p>
</form>
Expand Down
33 changes: 33 additions & 0 deletions src/invenflask/templates/bulk_create_verify.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends 'base.html' %}

{% block content %}
<h1>{% block title %} Bulk Asset Create {% endblock %}</h1>
<p>Please select mapping of columns to asset info</p>
<form method="POST">
<label>Asset ID:</label>
<select class="form-control" name="asset_id" id="asset_id">
{% for header in headers_list %}
<option value="{{ header }}">{{ header }}</option>
{% endfor %}
</select>
<b>|</b>
<label>Asset Type:</label>
<select class="form-control" name="asset_type",id="assset_type">
{% for header in headers_list %}
<option value="{{ header }}">{{ header }}</option>
{% endfor %}
</select>
<b>|</b>
<label>Asset Status:</label>
<select class="form-control" name="asset_status" id="asset_status">
<option value="Available">Available</option>
{% for header in headers_list %}
<option value="{{ header }}">{{ header }}</option>
{% endfor %}
</select>
<button type="submit">Import</button>
</form>
{{ data_var|safe }}

{% endblock %}

80 changes: 0 additions & 80 deletions src/invenflask/templates/bulk_import_verify.html

This file was deleted.

22 changes: 11 additions & 11 deletions src/invenflask/templates/staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
<table id="Staff" class="table table-striped">
<thead>
<tr>
<th style="text-align:left">First Name</th>
<th style="text-align:left">Last Name</th>
<th style="text-align:left">Staff ID</th>
<th style="text-align:left">Division</th>
<th style="text-align:left">Department</th>
<th style="text-align:left">Title</th>
<th>First Name</th>
<th>Last Name</th>
<th>Staff ID</th>
<th>Division</th>
<th>Department</th>
<th>Title</th>
</tr>
</thead>
<tbody>
{% for staff in staffs %}
<tr>
<td>{{ staff.first_name }}</td>
<td>{{ staff.last_name }}</td>
<td>{{ staff.FirstName }}</td>
<td>{{ staff.LastName }}</td>
<td>{{ staff.id }}</td>
<td>{{ staff.division }}</td>
<td>{{ staff.department }}</td>
<td>{{ staff.title }}</td>
<td>{{ staff.Division }}</td>
<td>{{ staff.Department }}</td>
<td>{{ staff.Title }}</td>
</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit 7c9ebd4

Please sign in to comment.