stc

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

commit ba624740c055ee96373f3ce192fcaa03b8ec5a94
parent 952a0c371917edca7365ecc78b5bca21f9c7c47a
Author: Youth Employment Program Production <youthemployment22@gmail.com>
Date:   Sat, 20 Apr 2024 00:31:30 -0600

New Feature: Start of work on Equipment collection and page structure.

Diffstat:
Mapp/__init__.py | 3+++
Aapp/equipment/__init__.py | 5+++++
Aapp/equipment/__pycache__/__init__.cpython-310.pyc | 0
Aapp/equipment/__pycache__/forms.cpython-310.pyc | 0
Aapp/equipment/__pycache__/routes.cpython-310.pyc | 0
Aapp/equipment/forms.py | 11+++++++++++
Aapp/equipment/routes.py | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aapp/equipment/templates/dev.html | 0
Aapp/equipment/templates/equipment.html | 31+++++++++++++++++++++++++++++++
Aapp/equipment/templates/error.html | 0
Aapp/equipment/templates/form.html | 0
Aapp/equipment/update.py | 0
12 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/app/__init__.py b/app/__init__.py @@ -10,4 +10,7 @@ app.register_blueprint(meetings_bp) #app.register_blueprint(meetings_bp, url_pre from app.fleet import bp as fleet_bp app.register_blueprint(fleet_bp) #app.register_blueprint(fleet_bp, url_prefix='/fleet') +from app.equipment import bp as equipment_bp +app.register_blueprint(equipment_bp) #app.register_blueprint(equipment_bp, url_prefix='/equipment') + from app import routes, models diff --git a/app/equipment/__init__.py b/app/equipment/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +bp = Blueprint('equipment',__name__,template_folder='templates') + +from app.equipment import routes diff --git a/app/equipment/__pycache__/__init__.cpython-310.pyc b/app/equipment/__pycache__/__init__.cpython-310.pyc Binary files differ. diff --git a/app/equipment/__pycache__/forms.cpython-310.pyc b/app/equipment/__pycache__/forms.cpython-310.pyc Binary files differ. diff --git a/app/equipment/__pycache__/routes.cpython-310.pyc b/app/equipment/__pycache__/routes.cpython-310.pyc Binary files differ. diff --git a/app/equipment/forms.py b/app/equipment/forms.py @@ -0,0 +1,11 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, SelectField, DateField, FloatField +from wtforms.validators import DataRequired, optional, length, InputRequired, EqualTo + +class NewEquipment(FlaskForm): + equipment_type = SelectField("Type",validators=[DataRequired()]) + purchase_timestamp = DateField("Purchase Date",validators=[DataRequired()]) + purchase_price = FloatField("Purchase Price", validators=[optional()]) + match_percentage = FloatField("Percentage Match",validators=[optional()]) + purchasing_project = SelectField("Purchasing Project",validators=[optional()]) + submit_equipment = SubmitField("Submit Equipment") diff --git a/app/equipment/routes.py b/app/equipment/routes.py @@ -0,0 +1,97 @@ +from app import app +from flask_pymongo import PyMongo +from flask import render_template, redirect, url_for, flash, request +from flask_login import login_required +from bson.objectid import ObjectId +from app.equipment import bp +from app.equipment.forms import NewEquipment +import datetime + +mongo = PyMongo(app) + +## DEV and SEED Routes ## + +@bp.route("/dev/equipment",methods=["GET"]) +@login_required +def devEquipment(): + equipment = mongo.db.equipment_collection.find({}) + flash("dev=True") + return render_template("equipment.html",equipment=equipment,dev=True) + +@bp.route("/dev/seed/equipment",methods=["GET","PUT"]) +@login_required +def seedEquipment(): + seeds = [ + { # If equipment_type == "vehicle" pass data as params to NewVehicle(FlaskForm) to add additional details like vehicle_number + "equipment_type":"vehicle", + "branch":"Dillon", #TODO Change all references to branches to branch_id for scaling via a branch_collection + "vehicle_id": 1, + "purchase_timestamp": datetime.datetime.now(), + "purchase_price": 26500.68, + "match_percentage": 10.25, + "purchasing_project": ObjectId("647a3d95ab70a58f2a44a886") + }, + { + "equipment_type":"shovel", + "branch":"Salmon", + "purchase_timestamp": datetime.datetime.now(), + "purchase_price": 16.68, + "match_percentage": 2.5, + "purchasing_project": ObjectId("647a3d95ab70a58f2a44a886") + }, + { + "equipment_type":"vehicle", + "branch":"Salmon", + "vehicle_id": 2, + "purchase_timestamp": datetime.datetime.now(), + "purchase_price": 65238.2, + "match_percentage": 12.5, + "purchasing_project": ObjectId("647a3d95ab70a58f2a44a886"), + "retired":True + }, + { + "equipment_type":"chainsaw", + "gear_id":1, + "branch":"Dillon", + "purchase_timestamp": datetime.datetime.now(), + "purchase_price": 16.68, + "match_percentage": 2.5, + "purchasing_project": ObjectId("647a3d95ab70a58f2a44a886") + }, + { + "equipment_type":"chainsaw", + "gear_id":2, + "branch":"Dillon", + "purchase_timestamp": datetime.datetime.now(), + "purchase_price": 16.68, + "match_percentage": 2.5, + "purchasing_project": ObjectId("647a3d95ab70a58f2a44a886") + } + ] + mongo.db.equipment_collection.delete_many({}) + mongo.db.equipment_collection.insert_many(seeds) + return redirect(url_for("equipment.devEquipment")) + +## END ## + +@bp.route("/equipment") +@bp.route("/equipment/") +@login_required +def equipment(): + equipment = mongo.db.equipment_collection.find({}) + return render_template("equipment.html",equipment=equipment) + +#### TODO pymongo.errors.OperationFailure: A pipeline stage specification object must contain exactly one field. errorcode: 40323 +@bp.route("/equipment/<equipmentType>",methods=["GET"]) +@login_required +def EquipmentType(equipmentType): + equipment = mongo.db.equipment_collection.aggregate( [ + { + "$match": {"equipment_type":equipmentType}, + "$sort": { + "equipment_type":1, + "purchase_timestamp":1 + } + } + ] ) + return render_template("equipment.html",equipment=equipment) diff --git a/app/equipment/templates/dev.html b/app/equipment/templates/dev.html diff --git a/app/equipment/templates/equipment.html b/app/equipment/templates/equipment.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} + +{% block title %}Equipment{% 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> + {% for tool in equipment %} + {% if dev %} + {{ tool }} + {% else %} + <article style="padding-top:2em;margin:0;"> + {% for key,value in tool.items() %} + <div style="display:grid;grid-gap:2em; grid-auto-flow:column; grid-template-columns:min-content"> + <div>{{ key }}</div> + <div>{{ value }}</div> + </div> + {% endfor %} + </article> + {% endif %} + {% endfor %} + </section> +{% endblock %} diff --git a/app/equipment/templates/error.html b/app/equipment/templates/error.html diff --git a/app/equipment/templates/form.html b/app/equipment/templates/form.html diff --git a/app/equipment/update.py b/app/equipment/update.py