Categorize and manage different types of furniture products
Blueprint Not Currently RegisteredThe furniture type module code exists in app/catalogs/furniture_type/, but the blueprint is not currently registered in the application factory (app/__init__.py). To enable this catalog, add the following to create_app():
from .catalogs.furniture_type import furniture_type_bpapp.register_blueprint(furniture_type_bp, url_prefix='/furniture-types')
The Furniture Types catalog defines categories of furniture products manufactured by the system. Examples include tables, chairs, closets, and other furniture items. The code is implemented but requires blueprint registration to be accessible.
data = {"name": "Dining Table"}furniture_type = FurnitureTypeService.create(data)
Implementation from services.py:27:
@staticmethoddef create(data: dict) -> dict: name = data.get("name") if not name or not name.strip(): raise ValidationError("El nombre del tipo de mueble es requerido") name = name.strip() existing = FurnitureType.query.filter_by(name=name).first() if existing: raise ConflictError(f"Ya existe un tipo de mueble con el nombre '{name}'") furniture_type = FurnitureType(name=name) db.session.add(furniture_type) db.session.commit() return furniture_type.to_dict()
@staticmethoddef get_by_id(id_furniture_type: int) -> FurnitureType: furniture_type = FurnitureType.query.get(id_furniture_type) if not furniture_type: raise NotFoundError(f"No se encontró el tipo de mueble con ID {id_furniture_type}") return furniture_type
data = {"name": "Coffee Table"}FurnitureTypeService.update(id_furniture_type, data)
Implementation from services.py:83:
@staticmethoddef update(id_furniture_type: int, data: dict) -> dict: furniture_type = FurnitureTypeService.get_by_id(id_furniture_type) name = data.get("name") if not name or not name.strip(): raise ValidationError("El nombre del furniture_type es requerido") name = name.strip() existing = FurnitureType.query.filter( FurnitureType.name == name, FurnitureType.id_furniture_type != id_furniture_type ).first() if existing: raise ConflictError(f"Ya existe un tipo de mueble con el nombre '{name}'") furniture_type.name = name db.session.commit() return furniture_type.to_dict()
The FurnitureTypeForm class in app/catalogs/furniture_type/forms.py:10 defines the input form:
class FurnitureTypeForm(FlaskForm): name = StringField( "Nombre", validators=[ DataRequired(message="El nombre del tipo de mueble es requerido"), Length(max=50, message="El nombre no puede exceder 50 caracteres"), ], )
# Get all active furniture typesfurniture_types = FurnitureTypeService.get_all()for ft in furniture_types: print(f"ID {ft.id_furniture_type}: {ft.name}")