
- 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.
28 lines
No EOL
984 B
Python
28 lines
No EOL
984 B
Python
from ..temp import is_temp_id
|
|
|
|
class ValidatableMixin:
|
|
VALIDATION_LABEL = "entry"
|
|
|
|
@classmethod
|
|
def validate_state(cls, submitted_items: list[dict]) -> list[str]:
|
|
errors = []
|
|
label = cls.VALIDATION_LABEL or cls.__name__
|
|
|
|
for index, item in enumerate(submitted_items):
|
|
if not isinstance(item, dict):
|
|
errors.append(f"{label.capitalize()} #{index + 1} is not a valid object.")
|
|
continue
|
|
|
|
name = item.get("name")
|
|
if not name or not str(name).strip():
|
|
errors.append(f"{label.capitalize()} #{index + 1} is missing a name.")
|
|
|
|
raw_id = item.get('id')
|
|
if raw_id is not None:
|
|
try:
|
|
_ = int(raw_id)
|
|
except (ValueError, TypeError):
|
|
if not is_temp_id(raw_id):
|
|
errors.append(f"{label.capitalize()} #{index + 1} has invalid ID: {raw_id}")
|
|
|
|
return errors |