Change FOREIGN keys to User.ethereum_address to User.id, resolves #14

This commit is contained in:
yiorgos marinellis 2020-04-01 19:11:14 +02:00
parent fea6f23c0c
commit e78b1c5db3
4 changed files with 32 additions and 32 deletions

View file

@ -384,17 +384,17 @@ class Computer(Device):
""" """
ethereum_address = Column(CIText(), unique=True, default=None) ethereum_address = Column(CIText(), unique=True, default=None)
deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0) deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0)
owner_address = db.Column(CIText(), owner_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.ethereum_address), db.ForeignKey(User.id),
nullable=False, nullable=False,
default=lambda: g.user.ethereum_address) default=lambda: g.user.id)
author = db.relationship(User, primaryjoin=owner_address == User.ethereum_address) author = db.relationship(User, primaryjoin=owner_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_address = db.Column(CIText(), receiver_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.ethereum_address), db.ForeignKey(User.id),
nullable=True) nullable=True)
receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) receiver = db.relationship(User, primaryjoin=receiver_id == User.id)
deliverynote_address = db.Column(CIText(), nullable=True) deliverynote_address = db.Column(CIText(), nullable=True)
def __init__(self, chassis, **kwargs) -> None: def __init__(self, chassis, **kwargs) -> None:

View file

@ -126,9 +126,9 @@ class Computer(Device):
deposit = Integer(validate=f.validate.Range(min=0, max=100), deposit = Integer(validate=f.validate.Range(min=0, max=100),
description=m.Computer.deposit.__doc__) description=m.Computer.deposit.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id') # author_id = NestedOn(s_user.User,only_query='author_id')
owner_address = SanitizedStr(validate=f.validate.Length(max=42)) owner_id = UUID(data_key='ownerID')
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)
receiver_address = SanitizedStr(validate=f.validate.Length(max=42)) receiver_id = UUID(data_key='receiverID')
deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42)) deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42))

View file

@ -63,11 +63,11 @@ class Lot(Thing):
descendants. descendants.
""" """
deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0)
owner_address = db.Column(CIText(), owner_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.ethereum_address), db.ForeignKey(User.id),
nullable=False, nullable=False,
default=lambda: g.user.ethereum_address) default=lambda: g.user.id)
owner = db.relationship(User, primaryjoin=owner_address == User.ethereum_address) owner = db.relationship(User, primaryjoin=owner_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_address = db.Column(CIText(), receiver_address = db.Column(CIText(),

View file

@ -22,7 +22,7 @@ class Lot(Thing):
deposit = f.Integer(validate=f.validate.Range(min=0, max=100), deposit = f.Integer(validate=f.validate.Range(min=0, max=100),
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')
owner_address = SanitizedStr(validate=f.validate.Length(max=42)) owner_id = f.UUID(data_key='ownerID')
transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)
receiver_address = SanitizedStr(validate=f.validate.Length(max=42)) receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True) deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True)