class PaintColor(db.Model): id = db.Column(db.Integer, primary_key=True) paint_id = db.Column(db.Integer, db.ForeignKey('paint.id'), nullable=False) color_id = db.Column(db.Integer, db.ForeignKey('color.id'), nullable=False) prod_code = db.Column(db.String(15)) base = db.Column(db.String(15)) formula = db.Column(db.String(100)) def __repr__(self): return f"PaintColor('{self.id}', '{self.paint_id}', '{self.color_id}')"
class Product(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) brand_id = db.Column(db.Integer, db.ForeignKey('brand.id')) paints = db.relationship('Paint', backref='product', lazy='dynamic') def __repr__(self): return f"Product('{self.id}', '{self.name}', '{self.brand_id}')"
class Project(db.Model): id = db.Column(db.Integer, primary_key=True) client_id = db.Column(db.Integer, db.ForeignKey('client.id')) site_id = db.Column(db.Integer, db.ForeignKey('site.id')) # A project is generally part of just 1 area, but sometimes it could span multiple areas. # Project can have many areas area_list = db.relationship('Area', secondary=project_area, backref=db.backref('projects', lazy='dynamic'), lazy='dynamic') # Many-to-Many Relationship # Project can have many Rooms room_list = db.relationship('Room', secondary=project_room, backref=db.backref('projects', lazy='dynamic'), lazy='dynamic') # Many-to-Many Relationship status_id = db.Column(db.Integer, db.ForeignKey('status.id')) typeOfWork_id = db.Column(db.Integer, db.ForeignKey('worktype.id')) name = db.Column(db.String(100), nullable=False) description = db.Column(db.String(250)) date_start = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date_finished = db.Column(db.DateTime) target_end_date = db.Column(db.DateTime) hours_estimate = db.Column(db.Float) # curr_hours_actual = Sum(timesheet WHERE timesheet.project_id = project.id ) quote_amt = db.Column(db.Float) invoice_amt = db.Column(db.Float) labour = db.Column(db.Float) materials = db.Column(db.Float) # damage_level = relationship to DamageClass? damage_comment = db.Column(db.String(500)) extenuating_circumstances = db.Column(db.String(500)) timesheets = db.relationship('Timesheet', secondary=project_timesheet, backref=db.backref('project', lazy='dynamic'), lazy='dynamic') purchase_order = db.Column(db.String(50)) # for invoicing work_order = db.Column(db.String(50)) # # bm_proj_id = db.Column(db.String(50)) # Email subject line info for tracking def __repr__(self): return f"Project('{self.id}', '{self.name}', '{self.site_id}')"
class ColorSheet(db.Model): id = db.Column(db.Integer, primary_key=True) area_id = db.Column(db.Integer, db.ForeignKey('area.id'), nullable=False) name = db.Column(db.String(40), nullable=False, default='default_color_sheet.jpg') date_uploaded = db.Column(db.DateTime, default=datetime.utcnow) def __repr__(self): return f"ColorSheet('{self.area_id}', '{self.name}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Brand(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) supplier_id = db.Column(db.Integer, db.ForeignKey('supplier.id')) products = db.relationship('Product', backref='brand') paints = db.relationship('Paint', backref='brand') def __repr__(self): return f"Brand('{self.id}', '{self.name}', '{self.supplier_id}')" def __str__(self): return f"{self.name}"
class Room(db.Model): id = db.Column(db.Integer, primary_key=True) bm_id = db.Column(db.String(25)) name = db.Column(db.String(100), nullable=False) location = db.Column(db.String(50)) description = db.Column(db.String(100)) orig_paint_date = db.Column( db.DateTime ) # Create a column called orig_paint_date and give it the same values as date_last_paint date_last_paint = db.Column( db.DateTime ) # date_last_paint will only store the date of the most recent paint job. freq = db.Column(db.Integer) date_next_paint = db.Column(db.DateTime) # Calculated field site_id = db.Column(db.Integer, db.ForeignKey('site.id'), nullable=False) # A room is in 1 Area area_id = db.Column(db.Integer, db.ForeignKey('area.id'), nullable=False) def __repr__(self): return f"Room('{self.bm_id}', '{self.name}', '{self.site_id},' '{self.area_id}')"
class Paint(db.Model): __table_args__ = tuple( UniqueConstraint('supplier_id', 'brand_id', 'product_id', 'sheen_id', name='_paint_uc')) id = db.Column(db.Integer, primary_key=True) supplier_id = db.Column(db.Integer, db.ForeignKey('supplier.id'), nullable=False) brand_id = db.Column(db.Integer, db.ForeignKey('brand.id'), nullable=False) product_id = db.Column(db.Integer, db.ForeignKey('product.id'), nullable=False) sheen_id = db.Column(db.Integer, db.ForeignKey('sheen.id'), nullable=False) paintcolors = db.relationship('PaintColor', backref='paint', lazy='dynamic') def __repr__(self): return f"Paint('{self.id}', '{self.supplier_id}', '{self.brand_id}', '{self.product_id}', '{self.sheen_id}')"
class Timesheet(db.Model): id = db.Column(db.Integer, primary_key=True) date_of_work = db.Column(db.Date, nullable=False) date_submit = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) hours = db.Column(db.Float, nullable=False, default=0) comment = db.Column(db.String(200)) completed = db.Column(db.Boolean) # Flag for a completed work day approved = db.Column( db.Boolean, default=False, nullable=False) # Flag for Steve's approval of hours and project # When doing a refresh, you need to run the following # op.execute('UPDATE timesheet SET approved = false') # op.alter_column('timesheet', 'approved', nullable=False) # for it to back fill with false. def __repr__(self): return f"Timesheet('{self.id}', '{self.user_id}', '{self.project_id}')"
class Area(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) code = db.Column(db.String(10), nullable=False) site_id = db.Column(db.Integer, db.ForeignKey('site.id'), nullable=False) building = db.Column(db.String(100), nullable=False) # should probably have no default level = db.Column(db.String(2), nullable=False) # should probably have no default descriptor = db.Column(db.Text) color_sheets = db.relationship('ColorSheet', backref='color', lazy=True) color_sheet = db.Column(db.String(40), nullable=False, default='default_color_sheet.jpg') # An Area has many rooms rooms = db.relationship('Room', backref='area', lazy=True) # one-to-many relationship def __repr__(self): return f"<Area '{self.name} - {self.code}>" def __str__(self): return f"{self.name} ({self.code})"
return User.query.get(int(user_id)) return None @login_manager.unauthorized_handler def unauthorized(): flash('You must be logged in to view that page.', 'warning') return redirect(url_for('auth_bp.login')) # UserTimesheet many-to-many table user_timesheet = db.Table( 'user_timesheet', db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True), db.Column('timesheet_id', db.Integer, db.ForeignKey('timesheet.id'), primary_key=True)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) fName = db.Column(db.String(30), nullable=False) lName = db.Column(db.String(30), nullable=False) cellPhone = db.Column(db.String(20)) image_file = db.Column(db.String(40),