stc

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

.old.models.py (4117B)


      1 # Test enviroment added validators username
      2 #                 removed BaseModel
      3 #                 added jsonify
      4 #                 fixed datetime
      5 
      6 import datetime
      7 import uuid
      8 from flask import Flask, jsonify, request, redirect, session
      9 from fastapi.encoders import jsonable_encoder
     10 from passlib.hash import pbkdf2_sha256 # Replace with Brennen's hash when he finds it
     11 from typing import List, Optional
     12 from pydantic import Field, ValidationError, validator
     13 from app import db
     14 
     15 class Users:
     16 
     17     def start_session(self, user):
     18         del user['password']
     19         session['logged_in'] = True
     20         session['user'] = user
     21         return jsonify(user), 200
     22 
     23     def signup(self):
     24         print(request.form)
     25         users = {
     26             '_id': uuid.uuid4().hex,
     27             'username': request.form.get('Username'),
     28             'password': request.form.get('Password'),
     29             'role': request.form.get('Role'),
     30             'location': request.form.get('Primary Location'),
     31             'phone': request.form.get('Phone Number'),
     32             'email': request.form.get('Email'),
     33             'pay_period': request.form.get('Pay Period'),
     34             'pay_value': request.form.get('Pay Value'),
     35         }
     36     
     37         # users['password'] = pbkdf2_sha256.encrypt(users['password'])
     38     
     39         return jsonify(users), 200
     40 
     41     def signout(self):
     42         session.clear()
     43         return redirect('/login')
     44 
     45     # def login(self):
     46     #     users = db.users.find_one({
     47     #         'email': request.form.get('email')
     48     #     })
     49 
     50     #     if users and pbkdf2_sha256.verify(request.form.get('password'), users['password']):
     51     #         return self.start_session(users)
     52 
     53     #     return jsonify({ 'error': 'Invalid login' }), 401
     54 
     55     @validator('username')
     56     def username_alphanumeric(cls, v):
     57         assert v.isalnum(), 'Username must be alphanumeric'
     58         return v
     59 
     60 class Time:
     61 
     62     def clockin(self):
     63         clockin = {
     64             '_id': int,
     65             'clock_in': Optional[datetime.datetime.utcnow],
     66             'date': Optional[datetime.date],
     67             'project': str,
     68             'note': str,
     69         }
     70 
     71         return jsonify(clockin), 200
     72 
     73     def clockout(self):
     74         clockout = {
     75             '_id': int,
     76             'clock_out': Optional[datetime.datetime.utcnow],
     77             'date': Optional[datetime.date],
     78             'project': str,
     79             'note': Optional[str],
     80             'total_time': int
     81         }
     82 
     83         return jsonify(clockout), 200
     84 
     85     _id: int
     86     # forign key
     87     clock_in: Optional[datetime.datetime.utcnow] #System time
     88     modified_by: str #link to _id of user
     89     date: Optional [datetime.date]
     90     project: str
     91     clock_out: Optional[datetime.datetime.utcnow] #System time
     92     note: str
     93     perdium: bool
     94     total_time: int #clock_out - clock_in
     95 
     96     def to_json(self):
     97         return jsonable_encoder(self, exclude_none=True)
     98 
     99     def to_bson(self):
    100         data = self.dict(by_alias=True, exclude_none=True)
    101 
    102         if data["_id"] is None:
    103             data.pop("_id")
    104         return data
    105 
    106 
    107 class Fleet:
    108     _id: int
    109     date: Optional[datetime.datetime.utcnow]
    110     operator: int #forign key to userID
    111     safety_checks: bool #array for different safety checks
    112     additional_notes: str
    113     vehicle: int #vehicleID
    114     incident_report: str
    115     mileage: int
    116 
    117     def to_json(self):
    118         return jsonable_encoder(self, exclude_none=True)
    119 
    120     def to_bson(self):
    121         data = self.dict(by_alias=True, exclude_none=True)
    122 
    123         if data["_id"] is None:
    124             data.pop("_id")
    125         return data
    126 
    127 
    128 class Agreement:
    129     _id: int #forign key to user
    130     start_date: int
    131     end_date: int
    132     bid_document: str #Filepath to document
    133     budget: float
    134     cost: int
    135 
    136 class Projects:#Projects references agreement
    137     project_id: int
    138     project_name: str
    139     project_budget: List[float] = [
    140         # labor_budget: float  | Indexed 0
    141         # travel_budget: float  | Indexed 1
    142         # supplies_budget: float  | Indexed 2
    143         # contact_budget: float  | Indexed 3
    144         # equipment_budget: float  | Indexed 4
    145         # other: float  | Indexed 5
    146     ]