Skip to content

Items

pydatalab.models.items

Classes

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; check that the refcode has the correct prefix if provided."""

        from pydatalab.config import CONFIG

        if v and not v.startswith(f"{CONFIG.IDENTIFIER_PREFIX}:"):
            raise ValueError(f"refcode missing prefix {CONFIG.IDENTIFIER_PREFIX!r}")

        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
Methods
refcode_validator(v) classmethod

Generate a refcode if not provided; check that the refcode has the correct prefix if 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; check that the refcode has the correct prefix if provided."""

    from pydatalab.config import CONFIG

    if v and not v.startswith(f"{CONFIG.IDENTIFIER_PREFIX}:"):
        raise ValueError(f"refcode missing prefix {CONFIG.IDENTIFIER_PREFIX!r}")

    return v