Skip to content

Commit

Permalink
Merge pull request #29 from drahamim/21-ability-to-create-staff-that-…
Browse files Browse the repository at this point in the history
…are-outside-regular-org

21 ability to create staff that are outside regular org
  • Loading branch information
drahamim authored Feb 22, 2023
2 parents 69c4508 + 00fd6db commit 45faf64
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 12 deletions.
106 changes: 95 additions & 11 deletions src/invenflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
os.makedirs(app.config['upload_folder'], exist_ok=True)
print(config_path)

print(app.config)
# print(app.config)


def get_db_connection():
Expand Down Expand Up @@ -122,14 +122,6 @@ def create_asset():
return render_template('create_asset.html')


@app.route('/status')
def status():
conn = get_db()
assets = conn.execute('SELECT * FROM assets').fetchall()
conn.commit()
return render_template('status.html', assets=assets)


@app.route('/<id>/edit/', methods=('GET', 'POST'))
def edit_asset(id):

Expand All @@ -150,7 +142,15 @@ def edit_asset(id):
return render_template('edit_asset.html', asset=asset, asset_types=asset_types)


@app.route('/delete/<id>/', methods=('POST',))
@app.route('/status')
def status():
conn = get_db()
assets = conn.execute('SELECT * FROM assets').fetchall()
conn.commit()
return render_template('status.html', assets=assets)


@app.route('/delete/<id>', methods=('POST',))
def delete(id):
asset = get_asset(id, "edit")
conn = get_db()
Expand All @@ -160,7 +160,91 @@ def delete(id):
return redirect(url_for('index'))


@app.route('/staff/', methods=('GET', 'POST'))
@app.route('/staff/create', methods=('GET', 'POST'))
def staff_create():
staff_div = "--"
staff_dept = "--"
if request.method == 'POST':
conn = get_db()
staff_id = request.form['staffid']
# auto_gen = request.form['staffgen']
first_name = request.form['firstname']
last_name = request.form['lastname']
staff_title = request.form['title']
if request.form['division']:
staff_div = request.form['division']
if request.form['department']:
staff_dept = request.form['department']

# if not staff_id and auto_gen != 'on':
if not staff_id:
flash('Staff ID or Auto Generate is required')
elif not first_name or not last_name:
flash('Missing Name information')
elif not staff_title:
flash('Missing Staff Title')
elif staff_id == get_staff(staff_id)['id']:
flash('Staff ID already exists. Try again.')
else:
# if auto_gen == 'on':
# last_staff = conn.execute(
# 'SELECT id FROM staffs order by length(id) desc, id desc limit 1'
# ).fetchone()['id']
# conn.commit()
# print(re.split("(\d+)", last_staff))
# next_staff_id = int(re.split("(\d+)", last_staff)[1]) + 1
# print(next_staff_id)
# staff_id = "SE" + str(next_staff_id)
# print(staff_id)
try:
conn = get_db()
conn.execute(
'INSERT INTO staffs (id, first_name, last_name, division, department, title)'
'VALUES(?,?,?,?,?,?)',
(staff_id, first_name, last_name,
staff_div, staff_dept, staff_title))
conn.commit()
return redirect(url_for('staff'))
except sqlite3.IntegrityError:
flash("Staff already exists")
return redirect(url_for('staff_create'))

return render_template('staff_create.html')


@app.route('/staff/delete/<id>/', methods=('POST',))
def staff_delete(id):
staff = get_staff(id)
conn = get_db()
conn.execute('DELETE FROM staffs WHERE id = ?', (staff,))
conn.commit()
flash('Staff "{}" was successfully deleted!'.format(id))
return redirect(url_for('staff'))


@app.route('/staff/edit/<id>/', methods=('GET', 'POST'))
def staff_edit(id):
if request.method == 'POST':
staff_id = id
first_name = request.form['firstname']
last_name = request.form['lastname']
staff_title = request.form['title']
staff_div = request.form['division']
staff_dept = request.form['department']

conn = get_db()
conn.execute(
'UPDATE staffs SET first_name = ?, last_name = ?, division = ?, department = ?, title = ? where id = ?',
(first_name, last_name, staff_div, staff_dept, staff_title, staff_id))
conn.commit()
return redirect(url_for('staff'))
if request.method == 'GET':
conn = get_db()
staff = get_staff(id)
return render_template('staff_edit.html', staff=staff)


@app.route('/staff', methods=('GET', 'POST'))
def staff():
conn = get_db()
if request.method == 'POST':
Expand Down
3 changes: 2 additions & 1 deletion src/invenflask/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
<a href="{{ url_for('checkin') }}">Check In</a>
<a href="{{ url_for('checkout') }}">Check Out</a>
<a href="{{ url_for('status') }}">Asset Status</a>
<a href="{{ url_for('history') }}">History</a>
<a href="{{ url_for('staff_create') }}">Create Staff</a>
<a href="{{ url_for('staff') }}">Staff</a>
<a href="{{ url_for('bulk_import') }}">Bulk Import</a>
<a href="{{ url_for('history') }}">History</a>
<!-- <a href="{{ url_for('status') }}">Asset Status</a>
<a href="{{ url_for('status') }}">Asset Status</a>
-->
Expand Down
1 change: 1 addition & 0 deletions src/invenflask/templates/staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<td>{{ staff.division }}</td>
<td>{{ staff.department }}</td>
<td>{{ staff.title }}</td>
<td><button type="button" onclick="document.location.href='/staff/edit/{{staff.id}}'">Edit</button>
</td>
</tr>
{% endfor %}
Expand Down
49 changes: 49 additions & 0 deletions src/invenflask/templates/staff_create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends 'base.html' %}

{% block content %}
<h1>{% block title %} Create Staff {% endblock %}</h1>
<form method="POST">
<label for="title">Staff ID</label>
<br>
<input type="text" name="staffid"
placeholder="Staff ID"
value="{{ request.form['staffid'] }}"></input>
<!-- <input type="checkbox" id="staffgen" name="staffgen"/>
<label for="staffgen">Auto Generate Staff ID</label> -->
<br>
<label for="title">First Name</label>
<br>
<input type="text" name="firstname"
placeholder="First Name"
value="{{ request.form['firstname'] }}"
required="required"></input>
<br>
<label for="title">Last Name</label>
<br>
<input type="text" name="lastname"
placeholder="Last Name"
value="{{ request.form['lastname'] }}"
required="required"></input>
<br>
<label for="title">Title</label>
<br>
<input type="text" name="title"
placeholder="Title"
value="{{ request.form['title'] }}"
required="required"></input>
<br>
<label for="title">Division</label>
<br>
<input type="text" name="division"
placeholder="Division"
value="{{ request.form['division'] }}"></input>
<br>
<label for="title">Department</label>
<br>
<input type="text" name="department"
placeholder="Department"
value="{{ request.form['department'] }}"></input>
<br>
<button type="submit">Submit</button>
</form>
{% endblock %}
44 changes: 44 additions & 0 deletions src/invenflask/templates/staff_edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% extends 'base.html' %}

{% block content %}
<h1>{% block title %} Edit {{ staff.id }} {% endblock %}</h1>
<form method="post">
<label for="title">Staff ID</label>
<br>
<label for="firstname">First Name</label>
<br>
<input type="text" name="firstname"
value="{{ staff.first_name }}">
</input>
<br>
<label for="title">Last Name</label>
<br>
<input type="text" name="lastname"
value="{{ staff.last_name }}">
</input>
<br>
<label for="title">Title</label>
<br>
<input type="text" name="title"
value="{{ staff.title }}">
</input>
<br>
<label for="title">Division</label>
<br>
<input type="text" name="division"
value="{{ staff.division }}">
</input>
<br>
<label for="title">Department</label>
<br>
<input type="text" name="department"
value="{{ staff.department }}">
</input>
<button type="submit">Submit</button>
</form>
<hr>
<form action="{{ url_for('staff_delete', id=staff.id) }}" method="POST">
<input type="submit" value="Delete Asset"
onclick="return confirm('Are you sure you want to delete this asset?')">
</form>
{% endblock %}

0 comments on commit 45faf64

Please sign in to comment.