stc

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

commit 0f6cc7741427c4c5a6b7945388be6c769e0fcb12
parent 5f8936420f0a374fa2e3c2f6e88257e4b33cbb51
Author: Youth Employment Program Production <youthemployment22@gmail.com>
Date:   Sat, 20 Apr 2024 00:23:12 -0600

More Fleet templating and additions

Diffstat:
Mapp/fleet/forms.py | 32+++++++++++++++++++++++++-------
Mapp/fleet/routes.py | 226+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Aapp/fleet/templates/fleet.html | 18++++++++++++++++++
Dapp/fleet/templates/meetings.html | 49-------------------------------------------------
4 files changed, 167 insertions(+), 158 deletions(-)

diff --git a/app/fleet/forms.py b/app/fleet/forms.py @@ -3,15 +3,15 @@ from wtforms import StringField, SubmitField, PasswordField, BooleanField, Selec from flask_wtf.file import FileField from wtforms.validators import DataRequired, optional, length, InputRequired, EqualTo -class NewMeeting(FlaskForm): - date = DateField('Meeting Date', validators=[DataRequired()]) - time = TimeField('Meeting Time', validators=[DataRequired()]) +#TODO +class NewFleet(FlaskForm): location = StringField('Meeting Link', validators=[DataRequired()]) expected_end = IntegerField('Expected Duration',default=60) meeting_description = StringField('Meeting Description') schedule_meeting = SubmitField('Schedule Meeting') -class UpdateMeeting(FlaskForm): +#TODO +class UpdateFleet(FlaskForm): date = DateField('Meeting Date') time = TimeField('Meeting Time') location = StringField('Meeting Link') @@ -19,6 +19,24 @@ class UpdateMeeting(FlaskForm): meeting_description = StringField('Meeting Description') update_meeting = SubmitField('Update Meeting') -class NewFileUpload(FlaskForm): - document = FileField('file') - submit_file = SubmitField('Submit File') +class FleetCheckoutForm(FlaskForm): + vehicle = SelectField('Vehicle', validators = [DataRequired()]) + start_mileage = IntegerField('Starting Mileage', validators=[DataRequired()]) #Require some sort of validator for check... + horn = BooleanField('Horn') + signals = BooleanField('Signals') + tires = BooleanField('Tires') + mirrors = BooleanField('Mirrors') + enginefluid = BooleanField('Engine Fluids') + steeringfluid = BooleanField('Steering Fluid') + brakefluid = BooleanField('Brake Fluid') + transmissionfluid = BooleanField('Transmission Fluid') + windshield = BooleanField('Windshield') + wipers = BooleanField('Windshield Wipers') + towingequipment = BooleanField('Towing Equipment') + additionalnotes = StringField('Additional Notes', validators=[optional()]) #May not need this at all? + checkout = SubmitField('Checkout Vehicle') #Update to take role name for pass to write fn + +class FleetCheckinForm(FlaskForm): + end_mileage = IntegerField('Ending Mileage',validators=[DataRequired()]) #Validation for end check + incident_notes = StringField('Incident Notes',validators=[optional()]) #May not need this at all? + checkin = SubmitField('Checkin Vehicle') diff --git a/app/fleet/routes.py b/app/fleet/routes.py @@ -6,7 +6,7 @@ from app.fleet import bp from bson.objectid import ObjectId import datetime, hashlib import os -from app.fleet.forms import NewMeeting, UpdateMeeting, NewFileUpload +from app.fleet.forms import NewFleet, UpdateFleet, FleetCheckoutForm, FleetCheckinForm #from app.meetings.update import #from app.meetings.meeting import @@ -14,66 +14,74 @@ mongo = PyMongo(app) ### Define fetch_meeting ### #TRY TO MOVE TO app.meetings.meeting.py -class MeetingNotFoundError(Exception): +class FleetNotFoundError(Exception): pass -def fetch_meeting(meeting_id): - meeting = mongo.db.meeting_collection.find_one({"meeting_id":meeting_id}) +def fetch_fleet(fleet_id): + fleet = mongo.db.fleet_collection.find({"fleet_id":fleet_id}) - if meeting == None: - raise MeetingNotFoundError(f'Meeting Id {meeting_id} returned None') + if fleet == None: + raise FleetNotFoundError(f'Fleet Id {fleet_id} returned None') else: - return meeting + return fleet ### BEGIN DEV ROUTES ### -@bp.route('/meetings/seed',methods=["GET","PUT"]) +@bp.route('/fleet/seed',methods=["GET","PUT"]) @login_required -def meetingSeed(): - expectedtime = datetime.datetime.now() - expectedtime1 = expectedtime + datetime.timedelta(minutes=60) - expectedtime2 = expectedtime - datetime.timedelta(minutes=60) - r1 = hashlib.sha256(os.urandom(16)).hexdigest() - r2 = hashlib.sha256(os.urandom(16)).hexdigest() +def fleetSeed(): + pj1 = "647a3d95ab70a58f2a44a886" + pj2 = "647a455f92e1af234bfb91b2" seeds = [ { - "meeting_id": r1, - "timestamp": datetime.datetime.now(), - "expected_end": expectedtime1, - "location": "https://www.brennen.work", - "documents":["/uploads/test.txt","/uploads/test2.pdf"], - "meeting_description":"Design Meeting" + "_id": "pool", + "available":[3,4,5], # list of _id where equipment_collection.find({}) type: is "vehicle" + "in_use":[(1,"brennentmazur"),(2,"nikolasmmazur")] #replace int with _id of equipment where "type": "vehicle" }, { - "meeting_id": r2, - "timestamp": datetime.datetime.now(), - "expected_end": expectedtime2, - "location": "https://www.brennen.work", - "documents":["/uploads/test2.doc"], - "minutes_file":"minutes.doc", - "meeting_description":"Design Meet" + "fleet_id": ObjectId(), + "branch":'Salmon', + "vehicle_number": 5, + "vehicle_name": 'Green Machine', + "mileage_start": 2, + "mileage_end": 6, + "project": ObjectId(pj1), + "operator":"brennentmazur", + "failed_checks":[] #appended from form where check is false on_validate + }, + { + 'fleet_id': ObjectId(), + 'branch':'Dillon', + "vehicle_number": 4, + "vehicle_name": 'Ram Machine', + "mileage_start": 622, + "mileage_end": 6999, + "project": ObjectId(pj1), + "operator":"brennentmazur", + "failed_checks":[] #appended from form where check is false on_validate } ] - mongo.db.meeting_collection.delete_many({}) - mongo.db.meeting_collection.insert_many(seeds) - dev_meetings = mongo.db.meeting_collection.find() - return render_template('dev.html',dev_meetings=dev_meetings) + mongo.db.fleet_collection.delete_many({}) + mongo.db.fleet_collection.insert_many(seeds) + dev_fleet = mongo.db.fleet_collection.find() + return render_template('dev.html',dev_fleet=dev_fleet) -@bp.route('/meetings/dev',methods=["GET"]) +@bp.route('/fleet/dev',methods=["GET"]) @login_required -def allMeetings(): - dev_meetings = mongo.db.meeting_collection.find({}) - return render_template('dev.html',dev_meetings=dev_meetings) +def allFleet(): + dev_fleet = mongo.db.fleet_collection.find({}) + return render_template('dev.html',dev_fleet=dev_fleet) ### END DEV ROUTES ### #### BEGIN ROUTES #### -@bp.route('/meetings',methods=["GET"]) -@bp.route('/meetings/',methods=["GET"]) +#TODO +@bp.route('/fleet',methods=["GET"]) +@bp.route('/fleet/',methods=["GET"]) @login_required -def meetings(): - ongoingMeetings = mongo.db.meeting_collection.aggregate( [ +def vehicles(): + ongoingFleet = mongo.db.fleet_collection.aggregate( [ { '$match':{ 'timestamp':{ @@ -87,7 +95,7 @@ def meetings(): { '$sort':{'timestamp':1}} ] ) - upcomingMeetings = mongo.db.meeting_collection.aggregate( [ + upcomingFleet = mongo.db.fleet_collection.aggregate( [ { '$match':{'timestamp':{'$gt': datetime.datetime.now() }} }, @@ -96,7 +104,7 @@ def meetings(): } ] ) - pastMeetings = mongo.db.meeting_collection.aggregate( [ + pastFleet = mongo.db.fleet_collection.aggregate( [ { '$match':{ 'timestamp': {"$lt": datetime.datetime.now()},'expected_end':{'$lt': datetime.datetime.now()} } }, @@ -107,13 +115,14 @@ def meetings(): '$limit':7 } ]) - return render_template('meetings.html',ongoingMeetings=ongoingMeetings,upcomingMeetings=upcomingMeetings,pastMeetings=pastMeetings) + return render_template('fleet.html',ongoingFleet=ongoingFleet,upcomingFleet=upcomingFleet,pastFleet=pastFleet) -@bp.route('/meetings/past',methods=["GET"]) +#TODO +@bp.route('/fleet/past',methods=["GET"]) @login_required def past(): - allOldMeetings = True - pastMeetings = mongo.db.meeting_collection.aggregate( [ + allOldFleet = True + pastFleet = mongo.db.fleet_collection.aggregate( [ { '$match':{'expected_end': {"$lt": datetime.datetime.now()} } }, @@ -121,105 +130,118 @@ def past(): '$sort':{ 'timestamp':-1 } } ] ) - return render_template('meetings.html',pastMeetings=pastMeetings, allOldMeetings=allOldMeetings) + return render_template('fleet.html',pastFleet=pastFleet, allOldFleet=allOldFleet) -@bp.route('/meeting/<meeting_id>',methods=["GET"]) -@bp.route('/meeting/<meeting_id>/',methods=["GET"]) -def meeting(meeting_id): +@bp.route('/fleet/<fleet_id>',methods=["GET"]) +@bp.route('/fleet/<fleet_id>/',methods=["GET"]) +def fleet(fleet_id): try: - meeting = fetch_meeting(meeting_id) - except MeetingNotFoundError as e: + fleet = fetch_fleet(fleet_id) + except FleetNotFoundError as e: return render_template('error.html',error=e) else: - return render_template('meeting.html',meeting=meeting) + return render_template('fleet.html',fleet=fleet) -@bp.route('/meeting/new',methods=["GET","POST"]) +#TODO +@bp.route('/fleet/new',methods=["GET","POST"]) @login_required def new(): - form = NewMeeting() + form = NewFleet() if form.validate_on_submit(): - m_id = hashlib.sha256(os.urandom(16)).hexdigest() - timestp = datetime.datetime.combine(form.date.data,form.time.data) - expectedtime = timestp + datetime.timedelta(minutes=form.expected_end.data) + #timestp = datetime.datetime.combine(form.date.data,form.time.data) +# "fleet_id": new ObjectId(), +# "branch":'Salmon', +# "vehicle_number": 5, +# "vehicle_name": 'Green Machine', +# "mileage_start": 2, +# "mileage_end": 6, +# "project": ObjectId(pj1), +# "operator":"brennentmazur", +# "failed_checks":[] #appended from form where check is false on_validate + #expectedtime = timestp + datetime.timedelta(minutes=form.expected_end.data) try: - new_meeting = {'meeting_id':m_id,'timestamp':timestp,'location':form.location.data,'expected_end':expectedtime} - if form.meeting_description.data != "": - new_meeting['meeting_description']=form.meeting_description.data + new_fleet = {'branch':form.branch.data,'vehicle_number':form.vehicle_number.data} + if form.vehicle_name.data != "": + new_fleet['vehicle_name']=form.vehicle_name.data except Exception: return "Error assigning form data" else: - mongo.db.meeting_collection.insert_one(new_meeting) - flash("Created new meeting!") - return redirect(url_for('meetings.meetings')) + mongo.db.fleet_collection.insert_one(new_fleet) + flash("Created new fleet vehicle!") + return redirect(url_for('fleet.vehicles')) # if form.name.data != "": # new_meeting['meeting_name']=form.name.data return render_template('new.html',form=form) -@bp.route('/meeting/<meeting_id>/upload',methods=["GET","POST"]) +#TODO DOES THIS NEED TO BE HERE? GAS RECIPTS? +@bp.route('/fleet/<fleet_id>/upload',methods=["GET","POST"]) @login_required -def upload(meeting_id): +def upload(fleet_id): try: - meeting = fetch_meeting(meeting_id) - except MeetingNotFoundError as e: + fleet = fetch_fleet(fleet_id) + except FleetNotFoundError as e: return render_template('error.html',error=e) else: form = NewFileUpload() upload = datetime.datetime.utcnow() if form.validate_on_submit(): flash("submitted") - mongo.db.meeting_collection.update_one({'_id':meeting['_id']},{'$push':{'documents':'brennen'}}) - return redirect(url_for('meetings.upload',meeting_id=meeting['meeting_id'])) - return render_template('upload.html',meeting=meeting,form=form,upload=upload) + mongo.db.fleet_collection.update_one({'_id':fleet['_id']},{'$push':{'documents':'brennen'}}) + return redirect(url_for('fleet.upload',fleet_id=fleet['fleet_id'])) + return render_template('upload.html',fleet=fleet,form=form,upload=upload) -@bp.route('/meeting/<meeting_id>/update',methods=["GET","POST"]) +#TODO +@bp.route('/fleet/<fleet_id>/update',methods=["GET","POST"]) @login_required -def update(meeting_id): +def update(fleet_id): try: - meeting = fetch_meeting(meeting_id) - except MeetingNotFoundError as e: + fleet = fetch_fleet(fleet_id) + except FleetNotFoundError as e: return render_template('error.html',error=e) else: - return render_template('update.html',meeting=meeting) + return render_template('update.html',fleet=fleet) -@bp.route('/meeting/<meeting_id>/<update>',methods=["GET","POST"]) +#TODO +@bp.route('/fleet/<fleet_id>/<update>',methods=["GET","POST"]) @login_required -def change(meeting_id,update): - form = UpdateMeeting() +def change(fleet_id,update): + form = UpdateFleet() try: - meeting = fetch_meeting(meeting_id) - except MeetingNotFoundError as e: + fleet = fetch_fleet(fleet_id) + except FleetNotFoundError as e: return render_template('error.html',error=e) else: if form.validate_on_submit(): if update == "date": - timestamp = datetime.datetime.combine(form.date.data,meeting['timestamp'].time()) - mongo.db.meeting_collection.update_one({'meeting_id':meeting['meeting_id']},{'$set':{'timestamp':timestamp}}) - flash("Updated Date from {} to {}".format(meeting['timestamp'],timestamp)) - return redirect(url_for('meetings.update',meeting_id=meeting['meeting_id'])) + timestamp = datetime.datetime.combine(form.date.data,fleet['timestamp'].time()) + mongo.db.fleet_collection.update_one({'fleet_id':fleet['fleet_id']},{'$set':{'timestamp':timestamp}}) + flash("Updated Date from {} to {}".format(fleet['timestamp'],timestamp)) + return redirect(url_for('fleet.update',fleet_id=fleet['fleet_id'])) if update == "time": - timestamp = datetime.datetime.combine(meeting['timestamp'].date(),form.time.data) - mongo.db.meeting_collection.update_one({'meeting_id':meeting['meeting_id']},{'$set':{'timestamp':timestamp}}) - flash("Updated Time from {} to {}".format(meeting['timestamp'],timestamp)) - return redirect(url_for('meetings.update',meeting_id=meeting['meeting_id'])) + timestamp = datetime.datetime.combine(fleet['timestamp'].date(),form.time.data) + mongo.db.fleet_collection.update_one({'fleet_id':fleet['fleet_id']},{'$set':{'timestamp':timestamp}}) + flash("Updated Time from {} to {}".format(fleet['timestamp'],timestamp)) + return redirect(url_for('fleet.update',fleet_id=fleet['fleet_id'])) if update == "location": - mongo.db.meeting_collection.update_one({'meeting_id':meeting['meeting_id']},{'$set':{'location':form.location.data}}) - flash("Updated location from {} to {}".format(meeting['location'],form.location.data)) - return redirect(url_for('meetings.update',meeting_id=meeting['meeting_id'])) + mongo.db.fleet_collection.update_one({'fleet_id':fleet['fleet_id']},{'$set':{'location':form.location.data}}) + flash("Updated location from {} to {}".format(fleet['location'],form.location.data)) + return redirect(url_for('fleet.update',fleet_id=fleet['fleet_id'])) if update == "description": - mongo.db.meeting_collection.update_one({'meeting_id':meeting['meeting_id']},{'$set':{'meeting_description':form.meeting_description.data}}) - flash("Updated description to {}".format(form.meeting_description.data)) - return redirect(url_for('meetings.update',meeting_id=meeting['meeting_id'])) - return render_template('form.html',meeting=meeting,update=update,form=form) + mongo.db.fleet_collection.update_one({'fleet_id':fleet['fleet_id']},{'$set':{'fleet_description':form.fleet_description.data}}) + flash("Updated description to {}".format(form.fleet_description.data)) + return redirect(url_for('fleet.update',fleet_id=fleet['fleet_id'])) + return render_template('form.html',fleet=fleet,update=update,form=form) -@bp.route('/meeting/<meeting_id>/remove',methods=["GET","POST"]) +#TODO +@bp.route('/fleet/<fleet_id>/remove',methods=["GET","POST"]) @login_required -def remove(meeting_id): +def remove(fleet_id): try: - meeting = fetch_meeting(meeting_id) - except MeetingNotFoundError as e: + fleet = fetch_fleet(fleet_id) + except FleetNotFoundError as e: return render_template('error.html',error=e) else: - mongo.db.meeting_collection.delete_one(meeting) - flash("Deleted meeting {}".format(meeting['meeting_description'])) - return redirect(url_for('meetings.meetings')) + mongo.db.fleet_collection.delete_one(fleet) + flash("Deleted fleet {} {}".format(fleet['fleet_number'],fleet['vehicle_name'])) + return redirect(url_for('fleet.vehicles')) diff --git a/app/fleet/templates/fleet.html b/app/fleet/templates/fleet.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} + +{% block title %}Fleet{% 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> + Woo Hoo, Fleet Page! + This page will be for checking out a vehicle + display the vehicle checks + </section> +{% endblock %} diff --git a/app/fleet/templates/meetings.html b/app/fleet/templates/meetings.html @@ -1,49 +0,0 @@ -{% extends 'base.html' %} - -{% block title %}Meetings{% 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> - {% if ongoingMeetings %} - <section class="ongoing"> - <h2 style="color:red">Ongoing</h2> - {% for ongoing in ongoingMeetings %} - <a href="{{ url_for('meetings.meeting',meeting_id=ongoing['meeting_id']) }}"><div class="action-button">{{ ongoing.timestamp.date().isoformat() }} <a style="color:red" href="{{ ongoing['location'] }}" target="_blank"><div class="action-button">Join</div></a></div> - <p>{{ ongoing['meeting_description'] }} </p> - <p>{{ ongoing['expected_end'].time().isoformat(timespec='minutes') }}</p> - </a> - {% endfor %} - </section> - {% endif %} - {% if upcomingMeetings %} - <section class="upcoming"> - <h2>Upcoming:</h2> - {%- for upcoming in upcomingMeetings %} - <a href="{{ url_for('meetings.meeting',meeting_id=upcoming['meeting_id']) }}"><div>{{ upcoming.timestamp.date().isoformat() }} @ {{ upcoming.timestamp.time().isoformat(timespec='minutes') }}</div> - <p>{{ upcoming['meeting_description'] }}</p> - </a> - {%- endfor %} - </section> - {% endif %} - {% if pastMeetings %} - <section> - <h2>Past Meetings:</h2> - {%- for meeting in pastMeetings %} - <div> - <a href="{{ url_for('meetings.meeting',meeting_id=meeting['meeting_id']) }}"><div>{{ meeting.timestamp.date().isoformat() }} @ {{ meeting.timestamp.time().isoformat(timespec='minutes') }}</div>{% if allOldMeetings %}<div>{{meeting['meeting_description']}}</div>{% endif %}</a> - </div> - {%- endfor %} - {% if not allOldMeetings %}<a href="{{ url_for('meetings.past') }}"class="action-button">View older meetings</a>{% endif %} - {% if allOldMeetings %}<a href="{{ url_for('meetings.meetings') }}"class="action-button">Back to meetings</a>{% endif %} - </section> - {% endif %} - <a href="{{ url_for('meetings.new') }}" class="action-button">Schedule Meeting</a> - </section> -{% endblock %}