stc

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

commit bf96e08770de0d97021b57eddcf2ded640613d89
parent 5873469b42de4f9636bb2ba6b17809c2c0f8c9a5
Author: Youth Employment Program Production <youthemployment22@gmail.com>
Date:   Tue, 23 Apr 2024 22:45:16 -0600

Refactor and abstract fns for branches

Diffstat:
Mapp/branches/__pycache__/routes.cpython-310.pyc | 0
Mapp/branches/routes.py | 6++++++
Mapp/routes.py | 27++++++++++++++++++---------
3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/app/branches/__pycache__/routes.cpython-310.pyc b/app/branches/__pycache__/routes.cpython-310.pyc Binary files differ. diff --git a/app/branches/routes.py b/app/branches/routes.py @@ -25,6 +25,12 @@ def fetch_branch(branch_id): else: return branch +def get_available_branches(): + availableBranches = [] + for branch in mongo.db.branch_collection.find(): + availableBranches.append((branch['_id'],branch['branch_name'])) + return availableBranches + ### BEGIN DEV ROUTES ### @bp.route('/branches/seed',methods=["GET","PUT"]) diff --git a/app/routes.py b/app/routes.py @@ -9,6 +9,7 @@ from flask import request 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.branches.routes import get_available_branches from app.models import User, Time, Fleet, Agreement, Projects from bson.objectid import ObjectId import bson.json_util as json_util @@ -25,6 +26,17 @@ mongo = PyMongo(app) login_manager = LoginManager(app) login_manager.login_view = 'login' +def get_available_projects(branch=None): + availableProjects = [("","Select Project")] + for project in mongo.db.projects_collection.find(): + if branch: + if 'branch' in project: + if project['branch'] == 'Global' or project['branch'] == branch: + availableProjects.append((project['_id'],project['project_name'])) + else: + availableProjects.append((project['_id'],project['project_name'])) + return availableProjects + #### #### ####### User Routes/Queries ####### #### #### @@ -240,9 +252,9 @@ def dashboard(): availableVehicles = mongo.db.fleet_collection.find_one({'_id':'Fleet Pool'},{'available':1})['available'] lastMileage = 103483 #currently gets ALL projects TODO make filter by available agreements/projects - availableProjects = [] - for project in mongo.db.projects_collection.find(): - availableProjects.append((project['_id'],project['project_name'])) + availableProjects = get_available_projects() + #for project in mongo.db.projects_collection.find(): + # availableProjects.append((project['_id'],project['project_name'])) # GET_CLOCKED out users clocked_out_active_users=[] clocked_in_active_users=[] @@ -1333,12 +1345,9 @@ def rename_project(project_id): def change_branch(collection,document_id): form = ChangeBranchForm() - #TODO MAKE BELOW WORK!!! Apply to other branch dependent areas - #branches = [] - #for branch in mongo.db.branch_collection.find(): - # branches.append((branch['_id'],branch['location'])) - #form.branch.choices = branches - form.branch.choices = ['Dillon','Salmon','Global'] + form.branch.choices = [("",'Select Branch'),("Global","Global")] + for branch in get_available_branches(): + form.branch.choices.append(branch) if form.validate_on_submit(): match collection: