Initial import: shopdb-flask multi-site asset platform
Flask + Vue rewrite of the classic-ASP shopdb, built as a plugin framework so sister GE Aerospace sites can adopt it. Product version 0.7.0-pre-0.8.0, plugin contract 0.11.0, 966 backend tests. Key entry points: - docs/INSTALL-WINDOWS-IIS.md - tested Windows + IIS install runbook (own-site and subpath deployment methods) - docs/PILOT-DEPLOY.md - production pilot: stand up + import + verify - docs/IMPORT-API.md - schema-agnostic legacy data import contract - scripts/site_imports/wjf/ - West Jefferson reference import loader - docs/adr/ - twelve accepted architecture decision records
This commit is contained in:
20
plugins/printers/models/__init__.py
Normal file
20
plugins/printers/models/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Printers plugin models."""
|
||||
|
||||
from .printer import Printer, PrinterType # Asset-based models
|
||||
from .printer_driver import PrinterDriver
|
||||
from .model_supply import ( # data-driven model -> toner/drum/waste mapping
|
||||
ModelSupply,
|
||||
SUPPLY_TYPES,
|
||||
SUPPLY_COLORS,
|
||||
CAPACITY_TIERS,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'Printer',
|
||||
'PrinterType',
|
||||
'PrinterDriver',
|
||||
'ModelSupply',
|
||||
'SUPPLY_TYPES',
|
||||
'SUPPLY_COLORS',
|
||||
'CAPACITY_TIERS',
|
||||
]
|
||||
56
plugins/printers/models/model_supply.py
Normal file
56
plugins/printers/models/model_supply.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""Model-to-supply mapping - data-driven toner/drum/waste part numbers.
|
||||
|
||||
Replaces the old hardcoded part-number table. Each row maps one printer
|
||||
model to one supply part (a toner of a given color and capacity tier, or a
|
||||
drum/waste/maintenance item). Lets new models and their toners be added
|
||||
through the API/UI without a code change.
|
||||
"""
|
||||
|
||||
from shopdb.api import db, BaseModel
|
||||
|
||||
|
||||
# allowed values, surfaced to the UI via the /supplies/meta endpoint
|
||||
SUPPLY_TYPES = ('toner', 'drum', 'waste', 'maintenance')
|
||||
SUPPLY_COLORS = ('black', 'cyan', 'magenta', 'yellow', 'none')
|
||||
CAPACITY_TIERS = ('standard', 'high', 'extrahigh', 'metered', 'dmo')
|
||||
|
||||
|
||||
class ModelSupply(BaseModel):
|
||||
"""One supply part belonging to one printer model."""
|
||||
__tablename__ = 'modelsupplies'
|
||||
|
||||
modelsupplyid = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
modelnumberid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('models.modelnumberid'),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
# toner, drum, waste, maintenance
|
||||
supplytype = db.Column(db.String(20), nullable=False, default='toner')
|
||||
# black, cyan, magenta, yellow, or none (drum/waste have no color)
|
||||
color = db.Column(db.String(20), nullable=False, default='none')
|
||||
# standard, high, extrahigh, metered, dmo
|
||||
capacitytier = db.Column(db.String(20), nullable=False, default='standard')
|
||||
|
||||
partnumber = db.Column(db.String(50), nullable=False)
|
||||
marketingname = db.Column(db.String(120))
|
||||
pageyield = db.Column(db.Integer, comment='Rated page yield at 5 percent coverage')
|
||||
notes = db.Column(db.Text)
|
||||
|
||||
model = db.relationship('Model', backref='supplies')
|
||||
|
||||
# one part number per model, no duplicates
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint('modelnumberid', 'partnumber', name='uq_modelsupply_part'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ModelSupply {self.partnumber} ({self.color}/{self.capacitytier})>"
|
||||
|
||||
def to_dict(self):
|
||||
data = super().to_dict()
|
||||
if self.model:
|
||||
data['modelnumber'] = self.model.modelnumber
|
||||
return data
|
||||
123
plugins/printers/models/printer.py
Normal file
123
plugins/printers/models/printer.py
Normal file
@@ -0,0 +1,123 @@
|
||||
"""Printer plugin models - new Asset-based architecture."""
|
||||
|
||||
from shopdb.api import db, BaseModel
|
||||
|
||||
|
||||
class PrinterType(BaseModel):
|
||||
"""
|
||||
Printer type classification.
|
||||
|
||||
Examples: Laser, Inkjet, Label, MFP, Plotter, etc.
|
||||
"""
|
||||
__tablename__ = 'printertypes'
|
||||
|
||||
printertypeid = db.Column(db.Integer, primary_key=True)
|
||||
printertype = db.Column(db.String(100), unique=True, nullable=False)
|
||||
description = db.Column(db.Text)
|
||||
icon = db.Column(db.String(50), comment='Icon name for UI')
|
||||
color = db.Column(db.String(20), comment='CSS color for UI/map markers')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PrinterType {self.printertype}>"
|
||||
|
||||
|
||||
class Printer(BaseModel):
|
||||
"""
|
||||
Printer-specific extension data (new Asset architecture).
|
||||
|
||||
Links to core Asset table via assetid.
|
||||
Stores printer-specific fields like type, Windows name, share name, etc.
|
||||
"""
|
||||
__tablename__ = 'printers'
|
||||
|
||||
printerid = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
# Link to core asset
|
||||
assetid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('assets.assetid', ondelete='CASCADE'),
|
||||
unique=True,
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
|
||||
# Printer classification
|
||||
printertypeid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('printertypes.printertypeid'),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
# Vendor
|
||||
vendorid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('vendors.vendorid'),
|
||||
nullable=True
|
||||
)
|
||||
modelnumberid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('models.modelnumberid'),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
# Network identity
|
||||
hostname = db.Column(
|
||||
db.String(100),
|
||||
comment='Network hostname'
|
||||
)
|
||||
|
||||
# Windows/Network naming
|
||||
windowsname = db.Column(
|
||||
db.String(255),
|
||||
comment='Windows printer name (e.g., \\\\server\\printer)'
|
||||
)
|
||||
sharename = db.Column(
|
||||
db.String(100),
|
||||
comment='CSF/share name'
|
||||
)
|
||||
|
||||
# Installation
|
||||
iscsf = db.Column(db.Boolean, default=False, comment='Is CSF printer')
|
||||
installpath = db.Column(db.String(255), comment='Driver install path')
|
||||
|
||||
# Printer PIN (for secure print)
|
||||
pin = db.Column(db.String(20))
|
||||
|
||||
# Features
|
||||
iscolor = db.Column(db.Boolean, default=False, comment='Color capable')
|
||||
isduplex = db.Column(db.Boolean, default=False, comment='Duplex capable')
|
||||
isnetwork = db.Column(db.Boolean, default=True, comment='Network connected')
|
||||
|
||||
# Relationships
|
||||
asset = db.relationship(
|
||||
'Asset',
|
||||
backref=db.backref('printer', uselist=False, lazy='joined')
|
||||
)
|
||||
printertype = db.relationship('PrinterType', backref='printers')
|
||||
vendor = db.relationship('Vendor', backref='printer_items')
|
||||
model = db.relationship('Model', backref='printer_items')
|
||||
|
||||
__table_args__ = (
|
||||
db.Index('idx_printer_type', 'printertypeid'),
|
||||
db.Index('idx_printer_hostname', 'hostname'),
|
||||
db.Index('idx_printer_windowsname', 'windowsname'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Printer {self.hostname or self.assetid}>"
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert to dictionary with related names."""
|
||||
result = super().to_dict()
|
||||
|
||||
# Add related object names
|
||||
if self.printertype:
|
||||
result['printertypename'] = self.printertype.printertype
|
||||
if self.vendor:
|
||||
result['vendorname'] = self.vendor.vendor
|
||||
if self.model:
|
||||
result['modelname'] = self.model.modelnumber
|
||||
if self.model.imageurl:
|
||||
result['imageurl'] = self.model.imageurl
|
||||
|
||||
return result
|
||||
33
plugins/printers/models/printer_driver.py
Normal file
33
plugins/printers/models/printer_driver.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Printer driver: a named link (SMB path or HTTP URL) to driver files."""
|
||||
|
||||
from shopdb.api import db
|
||||
|
||||
|
||||
class PrinterDriver(db.Model):
|
||||
__tablename__ = 'printerdrivers'
|
||||
|
||||
driverid = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(150), nullable=False)
|
||||
# SMB path (\\\\server\\share\\...) or HTTP URL to the driver package
|
||||
location = db.Column(db.String(500), nullable=False)
|
||||
description = db.Column(db.Text)
|
||||
# Optional: attach a driver to a specific printer model
|
||||
modelnumberid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('models.modelnumberid'),
|
||||
nullable=True
|
||||
)
|
||||
isactive = db.Column(db.Boolean, default=True, nullable=False)
|
||||
|
||||
model = db.relationship('Model')
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'driverid': self.driverid,
|
||||
'name': self.name,
|
||||
'location': self.location,
|
||||
'description': self.description,
|
||||
'modelnumberid': self.modelnumberid,
|
||||
'modelname': self.model.modelnumber if self.model else None,
|
||||
'isactive': bool(self.isactive),
|
||||
}
|
||||
Reference in New Issue
Block a user