add new attributes in Lot and User models

This commit is contained in:
jordi.nadeu 2019-12-16 19:17:30 +01:00
parent 58ff2e69e2
commit fa99283389
6 changed files with 14 additions and 4 deletions

View File

@ -70,7 +70,12 @@ 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)
receiver_id = db.Column(UUID(as_uuid=False),
db.ForeignKey(User.ethereum_address),
nullable=True,
default=lambda: g.user.ethereum_address)
receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address)
delivery_note_address = db.Column(CIText(), nullable=True)
def __init__(self, name: str, closed: bool = closed.default.arg,
description: str = None) -> None:

View File

@ -27,7 +27,9 @@ class Lot(Thing):
deposit = ... # type: Column
author_id = ... # type: Column
transfer_state = ... # type: Column
receiver = ... # type: Column
receiver_id = ... # type: Column
receiver = ... # type: relationship
delivery_note_address = ... # type: Column
def __init__(self, name: str, closed: bool = closed.default.arg) -> None:
super().__init__()

View File

@ -23,5 +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)
receiver = SanitizedStr(validate=f.validate.Length(max=42))
transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)
receiver_id = SanitizedStr(validate=f.validate.Length(max=42))

View File

@ -24,6 +24,7 @@ class User(Thing):
backref=db.backref('users', lazy=True, collection_class=set),
secondary=lambda: UserInventory.__table__,
collection_class=set)
ethereum_address = Column(UUID(as_uuid=False), unique=True)
# todo set restriction that user has, at least, one active db

View File

@ -17,6 +17,7 @@ class User(Thing):
password = ... # type: Column
token = ... # type: Column
inventories = ... # type: relationship
ethereum_address = ... # type: Column
def __init__(self, email: str, password: str = None,
inventories: Set[Inventory] = None) -> None:

View File

@ -19,6 +19,7 @@ class User(Thing):
description='Use this token in an Authorization header to access the app.'
'The token can change overtime.')
inventories = NestedOn(Inventory, many=True, dump_only=True)
ethereum_address = String(description='User identifier address inside the Blockchain')
def __init__(self,
only=None,