Skip to content

Commit

Permalink
Add ItemStatus and EquipmentStatus in models
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes committed Sep 3, 2024
1 parent 42b5c71 commit 9150110
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pydatalab/pydatalab/models/equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from pydantic import Field

from pydatalab.models.items import Item
from pydatalab.models.utils import (
EquipmentStatus,
)


class Equipment(Item):
Expand All @@ -21,3 +24,6 @@ class Equipment(Item):

contact: Optional[str]
"""Contact information for equipment (e.g., email address or phone number)."""

status: EquipmentStatus = Field(default=EquipmentStatus.WORKING)
"""The status of the equipment, indicating its current state."""
7 changes: 6 additions & 1 deletion pydatalab/pydatalab/models/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
IsoformatDateTime,
PyObjectId,
Refcode,
ItemStatus,
)


Expand Down Expand Up @@ -45,6 +46,9 @@ class Item(Entry, HasOwner, HasRevisionControl, IsCollectable, HasBlocks, abc.AB
file_ObjectIds: List[PyObjectId] = Field([])
"""Links to object IDs of files stored within the database."""

status: ItemStatus = Field(default=ItemStatus.PLANNED)
"""The status of the item, indicating its current state."""

@validator("refcode", pre=True, always=True)
def refcode_validator(cls, v):
"""Generate a refcode if not provided."""
Expand All @@ -54,6 +58,7 @@ def refcode_validator(cls, v):
id = None
prefix, id = v.split(":")
if prefix is None or id is None:
raise ValueError(f"refcode missing prefix or ID {id=}, {prefix=} from {v=}")
raise ValueError(
f"refcode missing prefix or ID {id=}, {prefix=} from {v=}")

return v
22 changes: 21 additions & 1 deletion pydatalab/pydatalab/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ class ItemType(str, Enum):
STARTING_MATERIALS = "starting_materials"


class ItemStatus(str, Enum):
"""An enumeration of the status of items"""

PLANNED = "planned"
ACTIVE = "active"
COMPLETED = "completed"
FAILED = "failed"


class EquipmentStatus(str, Enum):
"""An enumeration of the status of equipments"""

WORKING = "working"
BROKEN = "broken"
BEING_FIXED = "being_fixed"
DEFUNCT = "defunct"
NOT_BEING_FIXED = "not_being_fixed"


class KnownType(str, Enum):
"""An enumeration of the types of entry known by this implementation, should be made dynamic in the future."""

Expand Down Expand Up @@ -106,7 +125,8 @@ def __get_validators__(self):
def validate(self, v):
q = self.Q(v)
if not q.check(self._dimensions):
raise ValueError("Value {v} must have dimensions of mass, not {v.dimensions}")
raise ValueError(
"Value {v} must have dimensions of mass, not {v.dimensions}")
return q

@classmethod
Expand Down

0 comments on commit 9150110

Please sign in to comment.