Add inventory management templates and utility functions
- Created HTML templates for inventory index, layout, search, settings, table, user, and worklog. - Implemented utility functions for eager loading relationships in SQLAlchemy. - Added validation mixin for form submissions. - Updated project configuration files (pyproject.toml and setup.cfg) for package management.
This commit is contained in:
parent
602bb77e22
commit
9803db17ab
51 changed files with 76 additions and 16 deletions
68
inventory/models/users.py
Normal file
68
inventory/models/users.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
from typing import Any, List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
from .rooms import Room
|
||||
from .work_log import WorkLog
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, Identity, Integer, Unicode, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = 'Users'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
staff: Mapped[Optional[bool]] = mapped_column("Staff", Boolean, server_default=text('((0))'))
|
||||
active: Mapped[Optional[bool]] = mapped_column("Active", Boolean, server_default=text('((0))'))
|
||||
last_name: Mapped[Optional[str]] = mapped_column("Last", Unicode(255), nullable=True)
|
||||
first_name: Mapped[Optional[str]] = mapped_column("First", Unicode(255), nullable=True)
|
||||
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("Rooms.ID"), nullable=True)
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column("Supervisor", Integer, ForeignKey("Users.ID"))
|
||||
|
||||
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
||||
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||
|
||||
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='contact')
|
||||
location: Mapped[Optional['Room']] = relationship('Room', back_populates='users')
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='owner')
|
||||
|
||||
@property
|
||||
def full_name(self) -> str:
|
||||
return f"{self.first_name or ''} {self.last_name or ''}".strip()
|
||||
|
||||
def __init__(self, first_name: Optional[str] = None, last_name: Optional[str] = None,
|
||||
location_id: Optional[int] = None, supervisor_id: Optional[int] = None,
|
||||
staff: Optional[bool] = False, active: Optional[bool] = False):
|
||||
self.first_name = first_name
|
||||
self.last_name = last_name
|
||||
self.location_id = location_id
|
||||
self.supervisor_id = supervisor_id
|
||||
self.staff = staff
|
||||
self.active = active
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)}, " \
|
||||
f"location={repr(self.location)}, staff={self.staff}, active={self.active})>"
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'location_id': self.location_id,
|
||||
'supervisor_id': self.supervisor_id,
|
||||
'staff': self.staff,
|
||||
'active': self.active
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "User":
|
||||
return cls(
|
||||
staff=bool(data.get("staff", False)),
|
||||
active=bool(data.get("active", False)),
|
||||
last_name=data.get("last_name"),
|
||||
first_name=data.get("first_name"),
|
||||
location_id=data.get("location_id"),
|
||||
supervisor_id=data.get("supervisor_id")
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue