Skip to content

Items

pydatalab.models.items

Item (Entry, HasOwner, HasRevisionControl, IsCollectable, HasBlocks, ABC) pydantic-model

The generic model for data types that will be exposed with their own named endpoints.

Source code in pydatalab/models/items.py
class Item(Entry, HasOwner, HasRevisionControl, IsCollectable, HasBlocks, abc.ABC):
    """The generic model for data types that will be exposed with their own named endpoints."""

    refcode: Refcode = None  # type: ignore
    """A globally unique immutable ID comprised of the deployment prefix (e.g., `grey`)
    and a locally unique string, ideally created with some consistent scheme.
    """

    item_id: HumanReadableIdentifier
    """A locally unique, human-readable identifier for the entry. This ID is mutable."""

    description: Optional[str]
    """A description of the item, either in plain-text or a markup language."""

    date: Optional[IsoformatDateTime]
    """A relevant 'creation' timestamp for the entry (e.g., purchase date, synthesis date)."""

    name: Optional[str]
    """An optional human-readable/usable name for the entry."""

    files: Optional[List[File]]
    """Any files attached to this sample."""

    file_ObjectIds: List[PyObjectId] = Field([])
    """Links to object IDs of files stored within the database."""

    @validator("refcode", pre=True, always=True)
    def refcode_validator(cls, v):
        """Generate a refcode if not provided."""

        if v:
            prefix = None
            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=}")

        return v

__slots__ special

refcode: Refcode pydantic-field

item_id: HumanReadableIdentifier pydantic-field required

description: str pydantic-field

date: IsoformatDateTime pydantic-field

name: str pydantic-field

files: List[pydatalab.models.files.File] pydantic-field

file_ObjectIds: List[pydatalab.models.utils.PyObjectId] pydantic-field

refcode_validator(v) classmethod

Generate a refcode if not provided.

Source code in pydatalab/models/items.py
@validator("refcode", pre=True, always=True)
def refcode_validator(cls, v):
    """Generate a refcode if not provided."""

    if v:
        prefix = None
        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=}")

    return v