stc

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

commit 0c9b8eafb0d2fb902e8af29ad0831f3e3b2808af
parent b9a4e5ac1188a3cdf8ce7ad64b3babcffd60c3ab
Author: Brennen T. Mazur <brennen@madis.cool>
Date:   Sun, 19 Mar 2023 13:03:14 -0600

fixed routes report defs, progressed employee_report def to allow server start, added changehours form and seed functionality

Diffstat:
Mapp/forms.py | 11++++++++++-
Mapp/routes.py | 47+++++++++++++++++++++++++++--------------------
Mseeds.py | 55++++++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 89 insertions(+), 24 deletions(-)

diff --git a/app/forms.py b/app/forms.py @@ -1,5 +1,5 @@ from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField, PasswordField, BooleanField, SelectField, DateField, TelField, EmailField, FloatField, IntegerField +from wtforms import StringField, SubmitField, PasswordField, BooleanField, SelectField, DateField, TelField, EmailField, FloatField, IntegerField, TimeField from wtforms.validators import DataRequired, optional, length # Login class currently assumes mongodb collection(Users) with structure @@ -41,6 +41,15 @@ class PunchclockinWidget(FlaskForm): # IFF user.role is_in(trusted_role[]) then allow lunch minute definition clockin = SubmitField('Clock In') +class ChangeHoursForm(FlaskForm): + projectChg = SelectField('Project') + startTiChg = TimeField('Start') + endTimeChg = TimeField('End') + lunchBxChg = BooleanField('Lunch') + perDiemChg = BooleanField('Per Diem') + updateEntr = SubmitField('Update') + removeEntr = SubmitField('Remove') + class NewRoleForm(FlaskForm): rolename = StringField('Role Name', validators=[DataRequired()]) diff --git a/app/routes.py b/app/routes.py @@ -4,7 +4,7 @@ from app import app from flask_pymongo import PyMongo from flask_login import LoginManager from flask import render_template, url_for, request, flash, redirect -from app.forms import LoginForm, PunchclockinWidget, PunchclockoutWidget, FleetCheckoutForm, FleetCheckinForm, NewUserForm, AdmnPermissionsForm, DashPermissionsForm +from app.forms import LoginForm, PunchclockinWidget, PunchclockoutWidget, FleetCheckoutForm, FleetCheckinForm, NewUserForm, AdmnPermissionsForm, DashPermissionsForm, ChangeHoursForm from flask import request from werkzeug.urls import url_parse from werkzeug.security import generate_password_hash, check_password_hash @@ -278,34 +278,35 @@ def admin(): ####### Agreement Report Route ####### #### #### # Report Routes -@app.route('/admin/agreement') -@login_required -def agreement_report(): - return render_template ('admin/reports/agreement_report.html', ORGNAME=OrganizationName) + +#@app.route('/admin/agreement') +#@login_required +#def agreement_report(): +# return render_template ('admin/reports/agreement_report.html', ORGNAME=OrganizationName) #### #### ####### Employee Report Route ####### #### #### -@app.route('/admin/employee') -@login_required -def employee_report(): - return render_template ('admin/reports/employee_report.html', ORGNAME=OrganizationName) +#@app.route('/admin/employee') +#@login_required +#def employee_report(): +# return render_template ('admin/reports/employee_report.html', ORGNAME=OrganizationName) #### #### ####### Pay Period Report Route ####### #### #### -@app.route('/admin/pay-period') -@login_required -def pay_period_report(): - return render_template ('admin/reports/pay_period_report.html', ORGNAME=OrganizationName) +#@app.route('/admin/pay-period') +#@login_required +#def pay_period_report(): +# return render_template ('admin/reports/pay_period_report.html', ORGNAME=OrganizationName) #### #### ####### Vehicle Report Route ####### #### #### -@app.route('/admin/vehicle') -@login_required -def vehicle_report(): - return render_template ('admin/reports/vehicle_report.html', ORGNAME=OrganizationName) +#@app.route('/admin/vehicle') +#@login_required +#def vehicle_report(): +# return render_template ('admin/reports/vehicle_report.html', ORGNAME=OrganizationName) #### #### @@ -315,10 +316,14 @@ def vehicle_report(): @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) + #dashperms=mongo.db.permissions_collection.find_one({'label': current_user.role},{'dashboard':1,'_id':0}) + #dashperms=dashperms['dashboard'] + form = ChangeHoursForm() + projectChoices = mongo.db.project_collection.find({'completed':{'$exists':False}}) 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) + return render_template ('dashboard/punchclock/index.html',form=form,hours=hours,user=user,choices=projectChoices,ORGNAME=OrganizationName) # Don't really need this until additional functionality is added, not in current project scope #@app.route("/fleet") @@ -447,8 +452,10 @@ def pay_period_report(): @app.route('/admin/reports/employee/<username>') @login_required -def employee_report(): - return render_template ('admin/reports/employee_report.html', ORGNAME=OrganizationName) +def employee_report(username): + user = mongo.db.user_collection.find_one({"username": username}) + hours = mongo.db.time_collection.find({'modified_by.0':user['username']}) + return render_template ('admin/reports/employee_report.html', hours=hours, user=user, ORGNAME=OrganizationName) # Vehicle Routes @app.route('/admin/reports/vehicles') diff --git a/seeds.py b/seeds.py @@ -118,6 +118,9 @@ fleet2 = { # Agreement documents agreement1 = { + 'agreement_name': 'Agreement 1', + 'agency': ['USFS'], + 'projects': [2,3,4] 'start_date': '2023-12-5', 'end_date': '2023-8-12', 'bid_document': '/asset/document/agreements/New-Agreement.pdf', #Filepath to document @@ -126,6 +129,9 @@ agreement1 = { } agreement2 = { + 'agreement_name': 'Agreement 2', + 'agency': ['SMSP'], + 'projects': [1,5] 'start_date': '2021-2-21', 'end_date': '2022-12-13', 'bid_document': '/asset/document/agreements/Old-Agreement.pdf', #Filepath to document @@ -135,7 +141,9 @@ agreement2 = { # Projects documents projects1 = { - 'project_name': 'New Agreement', + '_id':1, + 'project_name': 'Project 1', + 'agreement': 2, 'project_budget': [13.20, 0, 20, 300, 50, 0 # labor_budget: float | Indexed 0 # travel_budget: float | Indexed 1 @@ -147,7 +155,9 @@ projects1 = { } projects2 = { - 'project_name': 'Old Agreement', + '_id':2, + 'project_name': 'Project 2', + 'agreement': 1, 'project_budget': [13.20, 0, 20, 300, 50, 0 # labor_budget: float | Indexed 0 # travel_budget: float | Indexed 1 @@ -158,6 +168,45 @@ projects2 = { ], } +projects3 = { + '_id':3, + 'project_name': 'Project 3', + 'agreement': 1, + 'project_budget': [13.20, 0, 20, 300, 50, 0 + # labor_budget: float | Indexed 0 + # travel_budget: float | Indexed 1 + # supplies_budget: float | Indexed 2 + # contact_budget: float | Indexed 3 + # equipment_budget: float | Indexed 4 + # other: float | Indexed 5 + ], +} +projects4 = { + 'project_name': 'Project 4', + '_id':4, + 'agreement': 1, + 'project_budget': [13.20, 0, 20, 300, 50, 0 + # labor_budget: float | Indexed 0 + # travel_budget: float | Indexed 1 + # supplies_budget: float | Indexed 2 + # contact_budget: float | Indexed 3 + # equipment_budget: float | Indexed 4 + # other: float | Indexed 5 + ], +} +projects5 = { + '_id':5, + 'project_name': 'Project 5', + 'agreement': 2, + 'project_budget': [13.20, 0, 20, 300, 50, 0 + # labor_budget: float | Indexed 0 + # travel_budget: float | Indexed 1 + # supplies_budget: float | Indexed 2 + # contact_budget: float | Indexed 3 + # equipment_budget: float | Indexed 4 + # other: float | Indexed 5 + ], +} # Permissions documents (only needs array list of str for each 'service') crew = { '_id':1, @@ -213,7 +262,7 @@ user_collection.insert_many([user1, user2]) time_collection.insert_many([time1, time2,time3]) fleet_collection.insert_many([fleet1, fleet2]) agreement_collection.insert_many([agreement1, agreement2]) -projects_collection.insert_many([projects1, projects2]) +projects_collection.insert_many([projects1, projects2, projects3, projects4, projects5]) permissions_collection.insert_many([crew,alead,lead,developer,manager,accountant]) # Print seeded data