From 0898a41e622643a74c1471d39703b3b4763b237a Mon Sep 17 00:00:00 2001 From: emmdim Date: Sat, 14 Dec 2019 22:11:28 +0100 Subject: [PATCH] Adds receiver column in Lot model and updates Lot views PATCH to be able to modify the needed values --- ereuse_devicehub/resources/lot/models.py | 1 + ereuse_devicehub/resources/lot/models.pyi | 2 ++ ereuse_devicehub/resources/lot/schemas.py | 3 ++- ereuse_devicehub/resources/lot/views.py | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index d9a037d8..39fd1804 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -71,6 +71,7 @@ class Lot(Thing): 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__ + receiver = db.Column(CIText(), default='', nullable=False) 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 80b2bbfb..e084a3fa 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -27,6 +27,7 @@ class Lot(Thing): deposit = ... # type: Column author_id = ... # type: Column transfer_state = ... # type: Column + receiver = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -41,6 +42,7 @@ class Lot(Thing): self.children = ... # type: Set[Lot] self.author_id = ... # type: UUID self.transfer_state = ... + self.receiver = ... # type: str 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 670a09a6..b9789021 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -23,4 +23,5 @@ class Lot(Thing): description=m.Lot.deposit.__doc__) # author_id = NestedOn(s_user.User,only_query='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 + tranfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) + receiver = SanitizedStr(validate=f.validate.Length(max=42)) \ No newline at end of file diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index dca07061..2e0b7e3e 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -40,7 +40,7 @@ class LotView(View): return ret def patch(self, id): - patch_schema = self.resource_def.SCHEMA(only=('name', 'description'), partial=True) + patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver', 'deposit'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() if lot.transfer_state.name == 'Initial':