Merge remote-tracking branch 'origin/mvp' into deliverynote

This commit is contained in:
jordi.nadeu 2019-12-12 15:50:09 +01:00
commit 9b22bcd8f6
4 changed files with 34 additions and 6 deletions

View file

@ -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

View file

@ -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):
@ -79,6 +80,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:

View file

@ -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

View file

@ -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)