Adds deposit and author is lot resources

This commit is contained in:
emmdim 2019-12-11 02:49:47 +01:00
parent 31357276ae
commit 856745ef91
3 changed files with 16 additions and 1 deletions

View File

@ -9,7 +9,7 @@ from sqlalchemy import TEXT
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy_utils import LtreeType from sqlalchemy_utils import LtreeType
from sqlalchemy_utils.types.ltree import LQUERY 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 teal.resource import url_for_resource
from ereuse_devicehub.db import create_view, db, exp, f 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 """All devices, including components, inside this lot and its
descendants. 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, def __init__(self, name: str, closed: bool = closed.default.arg,
description: str = None) -> None: description: str = None) -> None:

View File

@ -24,6 +24,8 @@ class Lot(Thing):
description = ... # type: Column description = ... # type: Column
all_devices = ... # type: relationship all_devices = ... # type: relationship
parents = ... # type: relationship parents = ... # type: relationship
deposit = ... # type: Column
author_id = ... # type: Column
def __init__(self, name: str, closed: bool = closed.default.arg) -> None: def __init__(self, name: str, closed: bool = closed.default.arg) -> None:
super().__init__() super().__init__()
@ -36,6 +38,7 @@ class Lot(Thing):
self.all_devices = ... # type: Set[Device] self.all_devices = ... # type: Set[Device]
self.parents = ... # type: Set[Lot] self.parents = ... # type: Set[Lot]
self.children = ... # type: Set[Lot] self.children = ... # type: Set[Lot]
self.author_id = ...
def add_children(self, *children: Union[Lot, uuid.UUID]): def add_children(self, *children: Union[Lot, uuid.UUID]):
pass pass

View File

@ -17,3 +17,9 @@ class Lot(Thing):
children = NestedOn('Lot', many=True, dump_only=True) children = NestedOn('Lot', many=True, dump_only=True)
parents = 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__) 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')