commit 46b42f765d1e8d7217121f098966e77d3fcc070a
parent 2d4f653c946a423726ec8057f894bf6886386640
Author: Brennen T. Mazur <brennen@madis.cool>
Date: Thu, 9 Mar 2023 14:11:10 -0700
display active users properly and style changes
Diffstat:
3 files changed, 83 insertions(+), 9 deletions(-)
diff --git a/app/routes.py b/app/routes.py
@@ -10,6 +10,8 @@ from werkzeug.urls import url_parse
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import current_user, login_user, logout_user, login_required
from app.models import User, Time, Fleet, Agreement, Projects
+#from .config import EXEMPT_METHODS
+import functools
OrganizationName = 'Youth Employment Program' # Maybe pass this as a value though the object for relevant pages???
@@ -58,6 +60,22 @@ def document():
@app.route('/projects/project', methods=['GET', 'POST', 'PUT'])
# Projects Routes / Queries
+##{{{{{{{{{{{{{{{{{{{{{ Decorator Functions }}}}}}}}}}}}}}}}}}}}}##
+#@login_required
+#def admin_required(func):
+# """Ensure logged in user has admin permissions"""
+# @functools.wraps(func)
+# def decorated_view(*args, **kwargs):
+# if current_user.role in :
+# pass
+# elif not current_user.role in :
+# return current_app.login_manager.unauthorized()
+#
+# #if not has_permission:
+# return func(*args, **kwargs)
+#
+# return decorated_view
+##{{{{{{{{{{{{{{{{{{{{{ END Decorator Functions }}}}}}}}}}}}}}}}}}}}}##
# Page Routes
@@ -110,6 +128,20 @@ def dashboard():
dashperms=dashperms['dashboard']
clocked_in_users = mongo.db.time_collection.find({'clock_out': {'$exists':False}})
+ def clock_user_out(time_id,lunch=False,perdiem=False):
+ if mongo.db.time_collection.find({'_id': time_id}, {'clock_out':{'$exists':False}}):
+ if lunch==True and perdiem==True:
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'lunch':True,'per_diem':True}})
+ elif lunch==True and perdiem==False:
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'lunch':True}})
+ elif lunch==False and perdiem==True:
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'per_diem':True}})
+ else:
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow()}})
+ return redirect(url_for('dashboard'))
+ else:
+ flash('No time entry found, or user has checked out already')
+ return redirect(url_for('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
@@ -144,10 +176,10 @@ def dashboard():
'operator':current_user.username,
'additional_notes':fleetoutform.additionalnotes.data})
return redirect(url_for('dashboard'))
- return render_template('dashboard/layout.html',permissions=dashperms,projects=available_projects,clocked_out=clocked_out,clockoutform=clockoutform,clockinform=clockinform,fleetinform=fleetinform,fleetoutform=fleetoutform,ORGNAME=OrganizationName)
+ return render_template('dashboard/layout.html',permissions=dashperms,projects=available_projects,clocked_out=clocked_out,clockoutform=clockoutform,clockinform=clockinform,fleetinform=fleetinform,fleetoutform=fleetoutform,clocked_in_users=clocked_in_users,ORGNAME=OrganizationName)
@app.route("/admin")
-@login_required
+#@admin_required
def admin():
adminperms=mongo.db.permissions_collection.find_one({'label': current_user.role},{'admin':1,'_id':0})
adminperms=adminperms['admin']
@@ -183,7 +215,7 @@ def vehicle_report():
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})
- return render_template ('dashboard/punchclock/index.html',user=user,ORGNAME=OrganizationName)
+ 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
#@app.route("/fleet")
@@ -216,6 +248,12 @@ def newuser():
if form.validate_on_submit():
genpasswd = ''.join(random.choice(string.ascii_letters) for _ in range(14))
+ # if form.payValue.data:
+ # value = form.payValue.data
+ # else:
+ # defined = mongo.db.permissions_collection.find_one({'label':form.role.data})
+ # value = defined.base_pay_value
+
mongo.db.user_collection.insert_one({
'fname':form.fname.data,
'mname':form.mname.data,
@@ -229,7 +267,7 @@ def newuser():
'address':form.address.data,
'email':form.email.data,
'pay_period':form.payPeriod.data,
- 'pay_value':form.payValue.data,
+ 'pay_value':form.role.data,
'is_active':form.setActive.data
})
flash("New user for {} {} added with a password of {}".format(form.fname.data, form.lname.data, genpasswd)) #Will need to sendmail password to form.email.data later
diff --git a/app/static/css/main.css b/app/static/css/main.css
@@ -90,9 +90,9 @@ header {
/* box-shadow: 0px 0px .1em .1em var(--accent);/* probably shouldn't have box-shadow for clean ui at intermediate page sizes (between laptop and phone off ratio) */
}
/********** FULL PAGE **********/
-.hours-grid, .new-user-grid, .role-permissions {
+.hours-grid, .new-user-grid, .role-permissions, .activeusers-grid {
padding:5rem;
- margin:0;
+ margin:1rem;
display: grid;
align-items: center;
justify-items: center;
@@ -100,6 +100,30 @@ header {
background-color: var(--widgetbg);
border-radius:.5em;
}
+
+/********** (In)Active Users PAGE **********/
+.activeusers-grid {
+ grid-auto-columns:auto;
+}
+.usercard {
+ border:1px solid;
+ border-color:var(--accent);
+ border-radius:.5em;
+ padding:0px;
+ margin:0px;
+}
+.activeusers-grid table,.activeusers-grid tr,.activeusers-grid td{
+ padding:1rem;
+}
+.activeusers-grid table tr:nth-child(even) {
+ background-color:var(--maincolor);
+}
+.activeusers-grid table td:nth-child(odd) {
+ text-align:left;
+}
+.activeusers-grid table td:nth-child(even) {
+ text-align:right;
+}
/********** WIDGETS **********/
.permissions, .reportswidget, .activeusers, .agreements, .fleet, .punchclock {
display: grid;
diff --git a/app/templates/admin/users/active.html b/app/templates/admin/users/active.html
@@ -3,9 +3,21 @@
{% block title %}All Active Users{% endblock %}
{% block content %}
+<section class="activeusers-grid">
{%- for user in activeusers %}
- {%- print(user) %}
- </br>
- </br>
+ <div class="usercard">
+ <h3>{{ user.fname }} {{ user.mname }} {{ user.lname }}</h3>
+ <table>
+ <tr><td>Username</td><td>{{ user.username }}</td></tr>
+ <tr><td>Birthday</td><td>{{ user.birthday }}</td></tr>
+ <tr><td>Role</td><td>{{ user.role }}</td></tr>
+ <tr><td>Branch</td><td>{{ user.branch }}</td></tr>
+ <tr><td>Phone Number</td><td>{{ user.phonenumber }}</td></tr>
+ <tr><td>Address</td><td>{{ user.address }}</td></tr>
+ <tr><td>Email</td><td>{{ user.email }}</td></tr>
+ <tr><td>Pay Value</td><td>{{ user.pay_value }}</td></tr>
+ </table>
+ </div>
{%- endfor %}
+</section>
{% endblock %}