From 856745ef91b899b49d1b8aa3275f837a169b3a51 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 11 Dec 2019 02:49:47 +0100 Subject: [PATCH] Adds deposit and author is lot resources --- ereuse_devicehub/resources/lot/models.py | 8 +++++++- ereuse_devicehub/resources/lot/models.pyi | 3 +++ ereuse_devicehub/resources/lot/schemas.py | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 5d08ab88..7e86b949 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -9,7 +9,7 @@ from sqlalchemy import TEXT 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 +from teal.db import CASCADE_OWN, UUIDLtree, check_range from teal.resource import url_for_resource from ereuse_devicehub.db import create_view, db, exp, f @@ -61,6 +61,12 @@ class Lot(Thing): """All devices, including components, inside this lot and its descendants. """ + deposit = db.Column(db.Integer, check_range('deposit',min=0,max=100), default=0) + author_id = db.Column(UUID(as_uuid=True), + db.ForeignKey(User.id), + nullable=False, + default=lambda: g.user.id) + author = db.relationship(User, primaryjoin=author_id == User.id) 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 2c820b0c..6101e9e9 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -24,6 +24,8 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship + deposit = ... # type: Column + author_id = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -36,6 +38,7 @@ class Lot(Thing): self.all_devices = ... # type: Set[Device] self.parents = ... # type: Set[Lot] self.children = ... # type: Set[Lot] + self.author_id = ... 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 c6550e86..6fd4f889 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -17,3 +17,9 @@ class Lot(Thing): children = NestedOn('Lot', many=True, dump_only=True) parents = NestedOn('Lot', many=True, dump_only=True) url = URL(dump_only=True, description=m.Lot.url.__doc__) + deposit = f.Integer(dump_only=True, + 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')