Changes author_id (uid) to owner_address (ethereum)

and receiver_id to receiver_address (just the name)
+ minor impvrovements
This commit is contained in:
emmdim 2019-12-19 01:38:03 +01:00 committed by nad
parent 6ef3e8dded
commit dd82f0e2d9
7 changed files with 35 additions and 31 deletions

View file

@ -382,18 +382,18 @@ class Computer(Device):
It is a subset of the Linux definition of DMI / DMI decode.
"""
deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0)
author_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id),
owner_address = db.Column(CIText(),
db.ForeignKey(User.ethereum_address),
nullable=False,
default=lambda: g.user.id)
author = db.relationship(User, primaryjoin=author_id == User.id)
default=lambda: g.user.ethereum_address)
author = db.relationship(User, primaryjoin=owner_address == User.ethereum_address)
transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False)
transfer_state.comment = TransferState.__doc__
receiver_id = db.Column(CIText(),
receiver_address = db.Column(CIText(),
db.ForeignKey(User.ethereum_address),
nullable=True)
receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address)
delivery_note_address = db.Column(CIText(), nullable=True)
receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address)
deliverynote_address = db.Column(CIText(), nullable=True)
def __init__(self, chassis, **kwargs) -> None:
chassis = ComputerChassis(chassis)

View file

@ -142,19 +142,20 @@ class Computer(DisplayMixin, Device):
components = ... # type: Column
chassis = ... # type: Column
deposit = ... # type: Column
author_id = ... # type: Column
owner_address = ... # type: Column
transfer_state = ... # type: Column
receiver_id = ... # type: Column
delivery_note_address = ... # type: Column
receiver_address = ... # type: Column
deliverynote_address = ... # type: Column
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.components = ... # type: Set[Component]
self.actions_parent = ... # type: Set[e.Action]
self.chassis = ... # type: ComputerChassis
self.author_id = ... # type: UUID
self.owner_address = ... # type: UUID
self.transfer_state = ...
self.receiver_id = ... # type: str
self.receiver_address = ... # type: str
self.deliverynote_address = ... # type: str
@property
def actions(self) -> List:

View file

@ -126,10 +126,10 @@ class Computer(Device):
data_key='deposit',
description=m.Computer.deposit.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id')
author_id = UUID(dump_only=True,
data_key='author_id')
owner_address = SanitizedStr(validate=f.validate.Length(max=42))
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)
receiver_id = SanitizedStr(validate=f.validate.Length(max=42))
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42))
class Desktop(Computer):

View file

@ -64,18 +64,18 @@ class Lot(Thing):
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),
owner_address = db.Column(CIText(),
db.ForeignKey(User.ethereum_address),
nullable=False,
default=lambda: g.user.id)
author = db.relationship(User, primaryjoin=author_id == User.id)
default=lambda: g.user.ethereum_address)
owner = db.relationship(User, primaryjoin=owner_address == User.ethereum_address)
transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False)
transfer_state.comment = TransferState.__doc__
receiver_id = db.Column(CIText(),
receiver_address = db.Column(CIText(),
db.ForeignKey(User.ethereum_address),
nullable=True)
receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address)
delivery_note_address = db.Column(CIText(), nullable=True)
receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address)
deliverynote_address = db.Column(CIText(), nullable=True)
def __init__(self, name: str, closed: bool = closed.default.arg,
description: str = None) -> None:

View file

@ -25,11 +25,12 @@ class Lot(Thing):
all_devices = ... # type: relationship
parents = ... # type: relationship
deposit = ... # type: Column
author_id = ... # type: Column
owner_address = ... # type: Column
owner = ... # type: relationship
transfer_state = ... # type: Column
receiver_id = ... # type: Column
receiver_address = ... # type: Column
receiver = ... # type: relationship
delivery_note_address = ... # type: Column
deliverynote_address = ... # type: Column
def __init__(self, name: str, closed: bool = closed.default.arg) -> None:
super().__init__()
@ -42,9 +43,10 @@ class Lot(Thing):
self.all_devices = ... # type: Set[Device]
self.parents = ... # type: Set[Lot]
self.children = ... # type: Set[Lot]
self.author_id = ... # type: UUID
self.owner_address = ... # type: UUID
self.transfer_state = ...
self.receiver_id = ... # type: str
self.receiver_address = ... # type: str
self.deliverynote_address = ... # type: str
def add_children(self, *children: Union[Lot, uuid.UUID]):
pass

View file

@ -22,6 +22,7 @@ class Lot(Thing):
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)
owner_address = 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))
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42))

View file

@ -41,10 +41,10 @@ class LotView(View):
return ret
def patch(self, id):
patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_id', 'deposit', 'delivery_note_address', 'devices', 'author_id'), partial=True)
patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'devices', 'owner_address'), partial=True)
l = request.get_json(schema=patch_schema)
lot = Lot.query.filter_by(id=id).one()
device_fields = ['transfer_state', 'receiver_id', 'deposit', 'delivery_note_address', 'author_id']
device_fields = ['transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'owner_address']
computers = [x for x in lot.all_devices if isinstance(x, Computer)]
for key, value in l.items():
setattr(lot, key, value)