diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index 9e74217c..956ead04 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -368,3 +368,25 @@ class ErasureStandards(Enum): and all(isinstance(step, actions.StepRandom) for step in other_steps): standards.add(cls.HMG_IS5) return standards + +@unique +class TransferState(Enum): + """State of transfer for a given Lot of devices. + """ + + """ + * Initial: No transfer action in place. + * Initiated: The transfer action has been initiated by orginator. + * Accepted: The transfer action has been accepted by destinator. + + Devicehub specially raises user awareness when an action + has a Severity of ``Warning`` or greater. + """ + + Initial = 0 + Initiated = 1 + Accepted = 2 + Completed = 3 + + def __str__(self): + return self.name diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 7e86b949..2087ed2b 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -5,17 +5,18 @@ from typing import Union from boltons import urlutils from citext import CIText from flask import g -from sqlalchemy import TEXT +from sqlalchemy import TEXT, Enum as DBEnum from sqlalchemy.dialects.postgresql import UUID from sqlalchemy_utils import LtreeType from sqlalchemy_utils.types.ltree import LQUERY -from teal.db import CASCADE_OWN, UUIDLtree, check_range +from teal.db import CASCADE_OWN, UUIDLtree, check_range, IntEnum from teal.resource import url_for_resource from ereuse_devicehub.db import create_view, db, exp, f from ereuse_devicehub.resources.device.models import Component, Device from ereuse_devicehub.resources.models import Thing from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.enums import TransferState class Lot(Thing): @@ -67,6 +68,8 @@ class Lot(Thing): nullable=False, default=lambda: g.user.id) author = db.relationship(User, primaryjoin=author_id == User.id) + transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) + transfer_state.comment = TransferState.__doc__ def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index 6101e9e9..4e410e58 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -26,6 +26,7 @@ class Lot(Thing): parents = ... # type: relationship deposit = ... # type: Column author_id = ... # type: Column + transfer_state = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -38,7 +39,8 @@ class Lot(Thing): self.all_devices = ... # type: Set[Device] self.parents = ... # type: Set[Lot] self.children = ... # type: Set[Lot] - self.author_id = ... + self.author_id = ... # type: UUID + self.transfer_state = ... def add_children(self, *children: Union[Lot, uuid.UUID]): pass diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index 6fd4f889..670a09a6 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -1,11 +1,12 @@ from marshmallow import fields as f -from teal.marshmallow import SanitizedStr, URL +from teal.marshmallow import SanitizedStr, URL, EnumField from ereuse_devicehub.marshmallow import NestedOn from ereuse_devicehub.resources.device import schemas as s_device from ereuse_devicehub.resources.lot import models as m from ereuse_devicehub.resources.models import STR_SIZE from ereuse_devicehub.resources.schemas import Thing +from ereuse_devicehub.resources.enums import TransferState class Lot(Thing): @@ -21,5 +22,5 @@ class Lot(Thing): data_key='deposit', description=m.Lot.deposit.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') - author_id = f.UUID(dump_only=True, - data_key='author_id') + author_id = f.UUID(dump_only=True) + tranfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) \ No newline at end of file