add new attributes in Lot and User models

This commit is contained in:
jordi.nadeu 2019-12-16 19:17:30 +01:00 committed by nad
parent 0898a41e62
commit a85ebf0a8b
6 changed files with 14 additions and 4 deletions

View file

@ -71,7 +71,12 @@ class Lot(Thing):
author = db.relationship(User, primaryjoin=author_id == User.id) author = db.relationship(User, primaryjoin=author_id == User.id)
transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False)
transfer_state.comment = TransferState.__doc__ 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, def __init__(self, name: str, closed: bool = closed.default.arg,
description: str = None) -> None: description: str = None) -> None:

View file

@ -27,7 +27,9 @@ class Lot(Thing):
deposit = ... # type: Column deposit = ... # type: Column
author_id = ... # type: Column author_id = ... # type: Column
transfer_state = ... # 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: def __init__(self, name: str, closed: bool = closed.default.arg) -> None:
super().__init__() super().__init__()

View file

@ -23,5 +23,5 @@ class Lot(Thing):
description=m.Lot.deposit.__doc__) description=m.Lot.deposit.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id') # author_id = NestedOn(s_user.User,only_query='author_id')
author_id = f.UUID(dump_only=True) author_id = f.UUID(dump_only=True)
tranfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)
receiver = SanitizedStr(validate=f.validate.Length(max=42)) 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), backref=db.backref('users', lazy=True, collection_class=set),
secondary=lambda: UserInventory.__table__, secondary=lambda: UserInventory.__table__,
collection_class=set) collection_class=set)
ethereum_address = Column(UUID(as_uuid=False), unique=True)
# todo set restriction that user has, at least, one active db # todo set restriction that user has, at least, one active db

View file

@ -17,6 +17,7 @@ class User(Thing):
password = ... # type: Column password = ... # type: Column
token = ... # type: Column token = ... # type: Column
inventories = ... # type: relationship inventories = ... # type: relationship
ethereum_address = ... # type: Column
def __init__(self, email: str, password: str = None, def __init__(self, email: str, password: str = None,
inventories: Set[Inventory] = None) -> 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.' description='Use this token in an Authorization header to access the app.'
'The token can change overtime.') 'The token can change overtime.')
inventories = NestedOn(Inventory, many=True, dump_only=True) inventories = NestedOn(Inventory, many=True, dump_only=True)
ethereum_address = String(description='User identifier address inside the Blockchain')
def __init__(self, def __init__(self,
only=None, only=None,