stc

a simple time card webapp
git clone _git@git.brennen.work:stc.git
Log | Files | Refs | README

commit 50be1f7861022adf925d6d6803981734295319a8
parent 7711c16ac48e77183cf63e33ed3407ffaf08e4b0
Author: Brennen T. Mazur <brennen@madis.cool>
Date:   Fri, 10 Mar 2023 00:03:30 -0700

late night fix time, fleet, newuser forms. No more default values for SelectFields

Diffstat:
Mapp/routes.py | 47++++++++++++++++++++++++++++++++---------------
Mapp/templates/admin/users/newuser.html | 5+++--
Mapp/templates/base.html | 1-
Mapp/templates/dashboard/fleet/widget.html | 4++++
Mapp/templates/dashboard/layout.html | 9+++++++++
Mapp/templates/dashboard/punchclock/index.html | 2+-
Mapp/templates/dashboard/punchclock/widget.html | 9+++++++--
7 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/app/routes.py b/app/routes.py @@ -124,6 +124,9 @@ def hello(): @login_required def dashboard(): + if datetime.datetime.date == current_user.birthday: + flash("Happy Birthday {}!").format(current_user.fname) + dashperms=mongo.db.permissions_collection.find_one({'label': current_user.role},{'dashboard':1,'_id':0}) dashperms=dashperms['dashboard'] @@ -145,6 +148,7 @@ def dashboard(): # Move to a isUserClockedIn(default: username=current_user) if mongo.db.time_collection.find_one({'modified_by.0': current_user.username,'clock_out':{'$exists':False}}): clocked_out = False + time_id = mongo.db.time_collection.find_one({'modified_by.0': current_user.username,'clock_out':{'$exists':False}})["_id"] else: clocked_out = True #End isUserClockedIn() @@ -154,6 +158,7 @@ def dashboard(): availableVehicles = ['Vehicle 1', 'Vehicle 2', 'Vehicle 3', 'Vehicle 4'] currentProject = 'Project 2' lastMilage = 103483 +# END default form values clockinform=PunchclockinWidget() clockoutform=PunchclockoutWidget() @@ -161,29 +166,39 @@ def dashboard(): fleetinform=FleetCheckinForm() clockinform.projectsSel.choices = availableProjects + clockinform.projectsSel.default = currentProject clockoutform.projectsSel.choices = availableProjects clockoutform.projectsSel.default = currentProject fleetoutform.vehicle.choices = availableVehicles + fleetoutform.vehicle.default = availableVehicles[0] fleetoutform.start_milage.default = lastMilage - clockinform.process() - clockoutform.process() - fleetoutform.process() - - if clockoutform.validate_on_submit(): - mongo.db.time_collection.insert({'clock_out' : [datetime.datetime.utcnow()], - 'lunch' : clockoutform.lunchBox.data, - 'per_diem' : clockoutform.per_diemBox.data}) +# Currently broken... appears to call constructor(wanted for setting default values) but regenerates csrf_token... clone fn without this call? or overload fn? Haven't looked at documentation yet + #clockinform.process() + #clockoutform.process() + #fleetoutform.process() + + #if clockoutform.validate_on_submit(): + #if request.method == 'POST' and clockoutform.validate(): + # mongo.db.time_collection.insert({'clock_out' : [datetime.datetime.utcnow()], + # 'lunch' : clockoutform.lunchBox.data, + # 'per_diem' : clockoutform.per_diemBox.data}) + # return redirect(url_for('dashboard')) + + #if clockinform.validate_on_submit(): Currently will submit all present forms... + if not clocked_out and request.method == 'POST' and clockoutform.validate(): + clock_user_out(time_id,clockoutform.lunchBox.data,clockoutform.per_diemBox.data) return redirect(url_for('dashboard')) - if clockinform.validate_on_submit(): - mongo.db.time_collection.insert({'clock_in' : [datetime.datetime.utcnow()], + if clocked_out and request.method == 'POST' and clockinform.validate(): + mongo.db.time_collection.insert_one({'clock_in' : [datetime.datetime.utcnow()], 'modified_by' : [current_user.username], 'date' : datetime.datetime.today(), - 'project' : clockinform.project.data}) + 'project' : clockinform.projectsSel.data}) return redirect(url_for('dashboard')) - if fleetoutform.validate_on_submit(): + #if fleetoutform.validate_on_submit(): + if request.method == 'POST' and fleetoutform.validate(): mongo.db.fleet_collection.insert_one({'date':datetime.datetime.today(), # NEED to work on modular way of storing safety checks... might condence to single true if all checked. else returns false and records false datavalue.label in incident_report[] If incident report, remove vehicle from available pool and display widget in admin layout 'vehicle':fleetoutform.vehicle.data, 'start_milage':fleetoutform.start_milage.data, @@ -227,8 +242,10 @@ def vehicle_report(): @app.route('/hours/<username>')#modify to take userid ex. /hours<userid> for "admin" currently pulls from current_user... simply always pass username to hours(if possible set a default to current_user) @login_required def hours(username):#userid goes into call to db to get user[] -> then returns formatted table (punchclock/index.html - user = load_user(username) - hours = mongo.db.time_collection.find({'modified_by.0':user.username}) + # user = load_user(username) + user = mongo.db.user_collection.find_one({"username": username}) + hours = mongo.db.time_collection.find({'modified_by.0':user['username']}) + #hours = mongo.db.time_collection.find({'modified_by.0':user.username}) return render_template ('dashboard/punchclock/index.html',hours=hours,user=user,ORGNAME=OrganizationName) # Don't really need this until additional functionality is added, not in current project scope @@ -270,7 +287,7 @@ def newuser(): form.branch.default = defaultBranch form.role.choices = availableRoles form.role.default = defaultRole - form.process() + #form.process() if form.validate_on_submit(): genpasswd = ''.join(random.choice(string.ascii_letters) for _ in range(14)) diff --git a/app/templates/admin/users/newuser.html b/app/templates/admin/users/newuser.html @@ -2,8 +2,6 @@ {% block title %}Add new Employee{% endblock %} -{% block navigation %}<a id="navi" href="/admin"><div id="back"><Back</div></a>{% endblock %} - {% block content %} <section class="new-user-grid"> <h3>Add New Employee</h3> @@ -12,6 +10,9 @@ {% for error in form.errors %} <span style="color:red;">[{{ error }}]</span> {% endfor %} + {% for ferror in form.form_errors %} + <span style="color:yellow;">[{{ ferror }}]</span> + {% endfor %} {{ form.fname.label }}{{ form.fname() }}<br> {{ form.mname.label }}{{ form.mname(size=1) }}<br> {{ form.lname.label }}{{ form.lname() }}<br> diff --git a/app/templates/base.html b/app/templates/base.html @@ -40,7 +40,6 @@ <!-- END DOCUMENTATION BUTTON --> <section class="appview"> {% block content %} {% endblock %} - <!-- functioncall for checking role IF logged in route /dashboard else LOGIN(templates/index.html) --> </section> <footer> diff --git a/app/templates/dashboard/fleet/widget.html b/app/templates/dashboard/fleet/widget.html @@ -1,6 +1,10 @@ <section class="fleet"> <h3>Fleet</h3> <form class="widget-form" action="" method="POST" novalidate> + {{ fleetoutform.hidden_tag() }} + {% for error in fleetoutform.errors %} + <span style="color:red;">[{{ error }}]</span> + {% endfor %} <div class="safetychecks"> {% for field in fleetoutform %} {{ field }}{% if field.widget.input_type != 'submit' and field.widget.input_type != 'hidden' %}{{ field.label }}{% endif %}<br> diff --git a/app/templates/dashboard/layout.html b/app/templates/dashboard/layout.html @@ -3,6 +3,15 @@ {% block title %}Dashboard{% endblock %} {% block content %} + +{% with messages = get_flashed_messages() %} +{% if messages %} + {% for message in messages %} + <div id="messagebanner"><p>{{ message }}</p></div> + {% endfor %} +{% endif %} +{% endwith %} + <section class="base-grid"> <!-- for loop takes current user's dashboard permissions and iterates through to include Accessable widgets, else reports lack of permissions --> {%- for x in permissions %} diff --git a/app/templates/dashboard/punchclock/index.html b/app/templates/dashboard/punchclock/index.html @@ -14,7 +14,7 @@ </br> </br> {% endfor %} - <form action="" method="post" novalidate> + <form action="" method="POST" novalidate> <input type="submit" value="Request Changes"> <input type="reset"> <table><!-- replace w/ function getUserHours(username) --> diff --git a/app/templates/dashboard/punchclock/widget.html b/app/templates/dashboard/punchclock/widget.html @@ -1,16 +1,21 @@ <section class="punchclock"> <h2 id="clock"></h2> + {% for error in clockoutform.errors or clockinform.errors %} + <span style="color:red;">[{{ error }}]</span> + {% endfor %} {% if clocked_out %} <form class="widget-form" action="" method="POST" novalidate> <div> - <p>{{ clockinform.projectsSel.label }}<br>{{ clockinform.projectsSel(choices=projects) }}</p> + {{ clockinform.hidden_tag() }} + <p>{{ clockinform.projectsSel.label }}<br>{{ clockinform.projectsSel() }}</p> <p>{{ clockinform.clockin() }}</p> </div> </form> {% elif not clocked_out %} <form class="widget-form" action="" method="POST" novalidate> <div> - <p>{{ clockoutform.projectsSel.label }}<br>{{ clockoutform.projectsSel(choices=projects) }}</p> + {{ clockoutform.hidden_tag() }} + <p>{{ clockoutform.projectsSel.label }}<br>{{ clockoutform.projectsSel() }}</p> <p>{{ clockoutform.lunchBox() }} {{ clockoutform.lunchBox.label }} {{ clockoutform.per_diemBox() }} {{ clockoutform.per_diemBox.label }}</p> <p>{{ clockoutform.clockout() }}</p>